滚动到底部时,向UITableView添加行 [英] Add rows to UITableView when scrolled to bottom

查看:85
本文介绍了滚动到底部时,向UITableView添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户滚动到 UITableView IBAction C $ C>?如果发生这种情况,我想添加更多行。我该怎么做?

Is there a way to trigger an event, such as with an IBAction, when a user scrolls to the bottom of a UITableView? I would like to add more rows if this happens. How do I do this?

推荐答案

只需听 scrollViewDidScroll:委托方法,将内容偏移量与当前可能的偏移量进行比较,如果低于某个阈值则调用您的方法来更新tableview。不要忘记调用 [tableView reloadData] 以确保重新加载新添加的数据。

Simply listen to the scrollViewDidScroll: delegate method, compare the content offset with the current possible offset and if lower then some threshold call your method to update the tableview. Don't forget to call [tableView reloadData] to make sure it reload the newly added data.

编辑:汇总抽象代码,不确定它是否有效,但应该。

Put together abstract code, not sure if it works, but should.

- (void)scrollViewDidScroll: (UIScrollView *)scroll {
     // UITableView only moves in one direction, y axis
     CGFloat currentOffset = scroll.contentOffset.y;
     CGFloat maximumOffset = scroll.contentSize.height - scroll.frame.size.height;

     // Change 10.0 to adjust the distance from bottom
     if (maximumOffset - currentOffset <= 10.0) {
          [self methodThatAddsDataAndReloadsTableView];
     }
}

这篇关于滚动到底部时,向UITableView添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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