NSFetchedResultsChangeUpdate crashes when called on a searched tableview
Posted
by
Zachary Fisher
on Stack Overflow
See other posts from Stack Overflow
or by Zachary Fisher
Published on 2012-06-04T13:29:43Z
Indexed on
2012/06/04
16:42 UTC
Read the original article
Hit count: 220
So I nearly have this thing figured out, but I am stumbling over the NSFetchedResultsChangeUpdate when I update my managedObjectContext from a detail view that was entered after searching the table.
I have a tableview generated from a core data set. I can enter a detail view from this table and make changes without any issue. I can also search the table and make changes MOST of the time without any issues. However, on certain objects, I get an "Exception was caught during Core Data change processing".
I tracked this down to the NSFetchedResultsChangeUpdate. I'm using the following code:
case NSFetchedResultsChangeUpdate:
if (searchTermForSegue)
{
NSLog(@"index info:%@.....",theIndexPath);
NSLog(@"crashing at the next line");
[self fetchedResultsController:self.searchFetchedResultsController configureCell:[tableView cellForRowAtIndexPath:theIndexPath] atIndexPath:theIndexPath];
break;
} else {
[self fetchedResultsController:controller configureCell:[tableView cellForRowAtIndexPath:theIndexPath] atIndexPath:theIndexPath]; }
break;
When the table is not being searched, it runs the else method and that works 100% of the time. When the table is being searched, it runs the if (searchTermForSegue) and that works most of the time, but not always. I logged theIndexPath and discovered the following:
When it works, theIndexPath is correctly reporting the objects indexPat, when it fails, the wrong theIndexPath has been called. For example, if I do a search that narrows the tableView to 3 sections, 2 items in first, 1 in second, 1 in third, I get the following nslog:
On first object: index info:<NSIndexPath 0xb0634d0> 2 indexes [0, 0].....
on second object: index info:<NSIndexPath 0xb063e70> 2 indexes [0, 1].....
on third object: index info:<NSIndexPath 0xb042880> 2 indexes [1, 0].....
but on the last object: index info:<NSIndexPath 0x9665790> 2 indexes [2, 17].....
it should be calling [2, 0]
Note that I am simply updating these objects, not deleting them or adding new ones.
Any thoughts would be appreciated!
© Stack Overflow or respective owner