UITableView keep the scroll at the correct position while updating NSFetchedResultsController
Asked Answered
R

1

8

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

Roping answered 1/7, 2012 at 16:48 Comment(3)
I'm trying to figure this out as well, nothing promising so far.Arwood
sound to me that you don't actually need infinite scrolling (table view supports that many rows) unless you actually need the data to compute row height.Utah
how do you compute the new offset versus the old? sounds to me this is the only problem leftUtah
P
1

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.

Pooler answered 11/3, 2014 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.