Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent NSFetchedResultsController from updating tableview when the controller disappears?

I have a UITabbar with multiple controllers in it. One of the controllers is used to add Events to Core Data, while another controller is used to display events as in a UITableView using NSFetchedResultsController.

Here's the behaviour that I would like to achieve: Upon disappearing, the UITableView stops updating, and when the user comes back, the entire table view is reloaded. Otherwise, inserting events from the other controller takes longer, as new rows are created in the UITableView, even thought it is not visible.

I'm wondering how I can achieve this behavior, as it doesn't seem to work as I expect it would be:

I have set the delegate of the NSFetchedResultsController to nil in viewWillDisappear, and restore it in viewWillAppear, along with a call to [UITableView reloadData];

Somehow, I do not see the new data, and suspect this is due to the way NSFetchedResultsController stops fetching if it does not have a delegate.

How can I properly "suspend" updates to UITableView when it disappears, but still able to see the entire dataset when the controller reappears?

like image 617
Alex Stone Avatar asked Nov 01 '12 23:11

Alex Stone


1 Answers

Try sending performFetch: to the NSFetchedResultsController in viewWillAppear: after you have set its delegate back to self.

like image 54
rob mayoff Avatar answered Sep 18 '22 02:09

rob mayoff