简体   繁体   中英

UITableView dynamic content loading when scrolling

I'm trying to implement an infinite 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.

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. 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. 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. So has someone some answer for this weird problem?

PS Or may be I should try reloadRowsAtIndexPaths instead of reloading the whole table?

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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