Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView keep the scroll at the correct position while updating NSFetchedResultsController

I am developing an iOS application that mainly use a UITableView. It retrieves pages of articles from a server. We have got >25000 articles; so I have implemented a pull-to-refresh and infinite scrolling to travel across the title collection. The ones downloaded persist using core data; NSFetchedResultsController is used to automatically update the UITableView.

However, I have implemented the infinite scrolling to be in both direction; up and down. Since the user will be allow to scroll down the 25000 article titles, I have to remove the one that the user has already scrolled. If the user scrolls up, I have to re-insert title above the current one. Doing so, I have got a moving window inside the article collection.

I display my articles by date group using the section and header.

The problem is that because the infinite scrolling goes in both direction, I often delete or add article at a higher position in the table. Infact to achieve that, I have got to change the predicate associated to NSFetchedResultsController.

This result by scroll being messed up. I have made it jump back to the position where it was supposed to be ish. It is not nice because it is a jump (animation:NO), if I put the animation ON, it goes all around the place before going back to the right position. And the position is not exactly the one it should be.

I am not sure I well explained my problem. I think the problem might be in the way I am using the UITableView but I am not sure how I should use it to make this better.

Cheers

like image 251
philouuuu Avatar asked Jul 01 '12 16:07

philouuuu


Video Answer


1 Answers

If you only store article titles in Core Data, I think it can handle 25.000 titles.

However I think that the problem you've got is with the pagination of the visible elements of the table

Here is a link that I used to handle something that you requested. You'll have to tweak a little bit to use Core Data and a remote source.

Please post some code if you can so we can have a look.

like image 134
javierfdezg Avatar answered Oct 26 '22 23:10

javierfdezg