简体   繁体   English

滚动时UITableView动态内容加载

[英]UITableView dynamic content loading when scrolling

I'm trying to implement an infinite UITableView. 我正在尝试实现一个无限的UITableView。 I load some information from the server in chunks and I want to dynamically add this information to the tableview when user scrolls the table. 我从服务器中加载了一些信息,当用户滚动表时,我想将这些信息动态添加到tableview中。

The problem I'm facing : I have an initial tableview with 40 elements and then in scrollViewDidScroll I check if last visible row's indexPath == [myData count] - 20 (so when user has already scrolled half of the list I load next content) I load next 40 elements of content from the server and only when last visible row's indexPath == [myData count] -1 I actually reload the tableview. 我面临的问题:我有一个包含40个元素的初始tableview,然后在scrollViewDidScroll检查是否最后一个可见行的indexPath == [myData count] - 20 (因此,当用户已经滚动列表的一半时,我将加载下一个内容)我从服务器加载内容的下40个元素,仅当last visible row's indexPath == [myData count] -1我才真正重新加载tableview。 So as you see i make some eager caching in order to make tableview reloading faster.Everything work perfectly but when I begin to scroll my table really fast data stopped loading. 因此,如您所见,我进行了一些急切的缓存操作,以使Tableview的重新加载速度更快。 It seems that this check: last visible row's indexPath == [myData count] - 20 has actually no chance to implement because of fast scrolling.I can't see any other obvious reasons for this. 看来,此检查: last visible row's indexPath == [myData count] - 20由于快速滚动实际上没有机会实现。我看不到任何其他明显的原因。 So has someone some answer for this weird problem? 那么有人为这个奇怪的问题提供了答案吗?

PS Or may be I should try reloadRowsAtIndexPaths instead of reloading the whole table? PS还是我应该尝试reloadRowsAtIndexPaths而不是重新加载整个表?

Maybe with this delegate you have a chance to do something in advance. 也许有了这个代表,您就有机会提前做些事情。 There is also possible to reload only the visible rows which it's better than reload data. 还可以只重载可见行,这比重载数据更好。

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    NSArray *paths = [self.tableView indexPathsForVisibleRows];
    int tmprow = [[paths objectAtIndex:0] row];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM