65.9K
CodeProject is changing. Read more.
Home

Avoid NSFetchedResultsController crashing app when popping

starIconstarIconemptyStarIconemptyStarIconemptyStarIcon

2.00/5 (1 vote)

Jan 5, 2012

CPOL
viewsIcon

14046

Stop app crashing with "-[MyClass controllerWillChangeContent:]: message sent to deallocated instance"?

Why is my app crashing with "-[MyClass controllerWillChangeContent:]: message sent to deallocated instance"? The accepted answer is to set the NSFetchedResultsController to nil when the view disappears.
-(void)viewWillDisappear:(BOOL)animated {
	self.fetchedResultsController = nil;
}
This, for me at least, resolved one problem and created a dozen more, Lists not displaying, deleting objects and alike. So I rolled back and took a closer look. The real problem occurred when I popped the UITableViewController. So taking the idea that setting the NSFetchedResultsController to nil could help, I set the NSFetchedResultsController to nil before popping the view and everything feel back into place.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	...
	self.fetchedResultsController = nil; //This is the line that fixed issue
	[self.navigationController popViewControllerAnimated:YES];
}
I hope this tip has helped. Rob