iOS 将新单元格动态加载到 tableview 的底部 [英] iOS dynamically load new cell to the bottom of a tableview
问题描述
我正在开发一个 iOS 项目,一旦用户到达底部,我想动态地将更多单元格添加到 tableview 的底部.我目前通过调用一个方法来获取更多数据,这些数据添加到我用来保存我的单元格的数组中.当我完成将对象添加到数组后,我调用 [tableView reloadData].这有效,但在 tableview 停止滚动之前它不会在视觉上加载单元格.
I'm working on an iOS project where I want to dynamically add more cell to the bottom of the tableview once the user reaches the bottom. I currently have this working by calling a method that fetches more data that is added to the array that I'm using to hold my cells. When I'm done adding the objects to the array I call [tableView reloadData]. This works, but it doesn't visually load the cell until the tableview stops scrolling.
我也尝试过使用 [tableView insertRowsAtIndexPaths: inSection:withRowAnimation: UITableViewRowAnimationNone].但是我得到了非常奇怪的行为,其中随机单元格会消失并且不会显示回来,直到我将 tableView 的那部分滚动到屏幕外,然后返回到该区域.
I also tried using [tableView insertRowsAtIndexPaths: inSection:withRowAnimation: UITableViewRowAnimationNone]. But I was getting very strange behavior where random cell would disappear and not show back up until I scrolled that section of the tableView off screen and then back to that area.
即使在调用 [tableView reloadDate] 时 tableView 仍在滚动中,有没有办法让 tableView 重新加载?
Is there a way to get the tableView to reload even if the tableView is still in mid scroll when the [tableView reloadDate] is called?
谢谢!
推荐答案
查看:如何知道 UITableView 何时在 iPhone 中滚动到底部neoneye 关于 - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { 的回答正是我想要的.在 NSLog(@"load more rows"); 之后,我移动了方法调用以获取更多单元格;
Check out: How to know when UITableView did scroll to bottom in iPhone neoneye's answer about - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { was exactly what I was looking for. I moved the method call to fetch more cell right after the NSLog(@"load more rows");
感谢 JiaYow 为我指引正确的方向!
Thank you JiaYow for steering me in the right direction!
这篇关于iOS 将新单元格动态加载到 tableview 的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!