UITableView 向下滚动和弹跳时调用哪个方法? [英] Which method called when UITableView scroll down and bounce?

查看:29
本文介绍了UITableView 向下滚动和弹跳时调用哪个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 XML 解析一些数据.我希望我的表格显示前 10 行,然后当用户滚动到底部并弹出表格时,它会更新(从 xml 加载新数据),然后显示新行.例如,首先用户得到 10 行,然后是其他 10 行,然后休息 10 行.

i parse some data from XML. I want my table to show first 10 rows, then when user scroll to bottom and table bounce, then it update (load new data from xml) and then show new rows. For example firstly user get 10 rows, then other 10, then rest 10.

我想知道tableview弹到底部时调用的是哪个方法,以及一些如何实现的建议,谢谢.

I want to know which method is called when tableview bounce to bottom, and some advice how to implement it, thank you.

推荐答案

UITableViewUIScrollView的子类,UITableViewDelegate符合<代码>UIScrollViewDelegate.所以你附加到table view的delegate会得到诸如scrollViewDidScroll:之类的事件,你可以在table view上调用诸如contentOffset之类的方法来找到滚动位置.

UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate. So the delegate you attach to the table view will get events such as scrollViewDidScroll:, and you can call methods such as contentOffset on the table view to find the scroll position.

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
    CGPoint offset = aScrollView.contentOffset;
    CGRect bounds = aScrollView.bounds;
    CGSize size = aScrollView.contentSize;
    UIEdgeInsets inset = aScrollView.contentInset;
    float y = offset.y + bounds.size.height - inset.bottom;
    float h = size.height;
    // NSLog(@"offset: %f", offset.y);   
    // NSLog(@"content.height: %f", size.height);   
    // NSLog(@"bounds.height: %f", bounds.size.height);   
    // NSLog(@"inset.top: %f", inset.top);   
    // NSLog(@"inset.bottom: %f", inset.bottom);   
    // NSLog(@"pos: %f of %f", y, h);

    float reload_distance = 10;
    if(y > h + reload_distance) {
        NSLog(@"load more rows");
    }
}

by 新人

这篇关于UITableView 向下滚动和弹跳时调用哪个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆