I have a TableViewController in my app (well several but this only happens on this particular one).
The content is driven from Core Data using an NSFetchedResultsController and the TVC is a NSFetchedResultsControllerDelegate and uses the methods for updating the table based on content changes (i.e. it runs the beginUpdates, endUpdates etc…).
I’ve done this a number of times before and so just use the same code. (Also can be found on Ray Wenderlich’s site).
Anyway, I have a view (pushed from the TVC) that adds new items in to the CoreData DB. This new item should then be added into the TVC’s table.
This is all working fine. I view the Table scroll up and down it fine. Click add. Add the new item. Push back to the TableView and I can see the new item…
BUT
The tableView doesn’t allow me to scroll all the way to the bottom now. I can see the new data in the table by scrolling to the bottom and holding the screen but when I let go the tableView bounces back so that I can no longer see it.
I have checked several things…
- The frame of the TableView is unchanged before and after.
- The contentSize of the tableView DOES change to accommodate the added cells.
- When scrolling the minimum contentOffset is 0 both before and after (this is correct).
- When scrolling the MAXIMUM contentOffset is the same both before and after (this is not correct).
If I pop back to the rootVC and then push back to the TVC then I can scroll all the way again and see all my new cells.
I did some testing.
If I re-enable autoRotating using - (BOOL)shouldAutorotate then go through the motions of adding the new cells etc then I still can’t scroll to the bottom. But if I rotate landscape and then back to portrait then now I can scroll all the way to the bottom.
Off the back of this I tried running the [self viewWillLayoutSubViews]; method after the [self.tableView endUpdates]; but still nothing.
Like I said, I have done this before many times and with no problems. I really don’t understand what is happening now.
I finally found a solution that worked!
In the end I had to put
[self.tableView reloadData];into theviewDidAppearmethod.That solved the problem.