I have a UITableViewController inside a UINavigationController, inside a UIPopoverController.
The UITableViewController uses a NSFetchedResultsController. didSelectRowAtIndexPath pushes another instance of my UITableViewController with a slightly different predicate onto the nav controller stack.
If I push a new UITableViewController on to the stack, and then pop it again, I will eventually get a EXC_BAD_ACCESS if I try to save an object that would have updated the tableview that was popped off.
As expected, setting the delegate of my NSFetchedResultsController to nil removes the EXC_BAD_ACCESS errors.
I am using ARC. So clearly these objects are getting released. This is OK. But why are they still getting notified when there is a change?
Code below. I am basically tracking the history of a web view in my database.
BookmarkViewController * bookmarkController = [[BookmarkViewController alloc] initWithStyle:UITableViewStylePlain andWebView:self.webView];
UINavigationController * bookmarkNavController = [[UINavigationController alloc] initWithRootViewController:bookmarkController];
self.bookmarkPopover = [[UIPopoverController alloc] initWithContentViewController:bookmarkNavController];
_bookmarkPopover.popoverContentSize = CGSizeMake(320, 44*10);
_bookmarkPopover.delegate = self;
bookmarkController.container=_bookmarkPopover;
bookmarkController.delegate=self;
The BookmarkViewController uses an NSFetchedResultsController and BookmarkViewController is the delegate of the NSFetchedResultsController.
- (NSFetchedResultsController *) myFetchedResultsController
{
if (self.fetchedResultsController != nil) {
return self.fetchedResultsController;
}
// Singleton
CoreDataManager * dataManager = [CoreDataManager defaultDataManager];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Bookmark" inManagedObjectContext:dataManager.managedObjectContext];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"label" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:self.predicate];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchBatchSize:20]; // Set the batch size to a suitable number.
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:dataManager.managedObjectContext
sectionNameKeyPath:@"type"
cacheName:nil];
self.fetchedResultsController.delegate = self;
return self.fetchedResultsController;
}
And also I have:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.tableView beginUpdates];
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.tableView endUpdates];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
BookmarkViewController * bookmarkViewController = [[BookmarkViewController alloc] initWithStyle:self.tableView.style
andWebView:self.webview
forFolder:bookmark.label];
[self.navigationController pushViewController:bookmarkViewController animated:YES];
}