Matt
Matt

Reputation: 1

Error when deleting from an NSFetchedResultsController controlled UITableView outside of the table view

I'm trying to remove an object managed by an NSFetchedResultsController in a UITableView - and I'm attempting to do so from a separate view via add/remove buttons. However, it seems as though controller and table are getting out of whack as I switch between views and I can't quit figure out why. Here is the error I am getting - unfortunately it doesn't always happen depending upon what path I take through the application:

Serious application error. Exception was caught during Core Data change processing: *** -[NSCFArray removeObjectAtIndex:]: index (6) beyond bounds (6) with userInfo (null)

I can see my delegate methods getting called correctly and the delete code is very straightforward and I don't see any errors there.

Any thoughts/debugging hints would be much appreciated.

Upvotes: 0

Views: 1576

Answers (2)

Sprintup
Sprintup

Reputation: 93

I'm not sure if we had the same issue, but my issue was solved with the following:

(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.fetchedResultsController.sections.count;}

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
return [sectionInfo numberOfObjects];}

Upvotes: 0

Patrice
Patrice

Reputation: 183

I encountered a similar problem. The only solution I found so far is to re-fetched the NSFetchedResultsController:

if (![[self resultsController] performFetch:&error]) {
   NSLog(@"%@:%s Error refreshing the fetch controller %@", [self class], _cmd, 
      [error localizedDescription]);
   NSAssert(NO, @"Failed to refresh the fetch controller");
}

Upvotes: 1

Related Questions