NSFetchedResultsController returning objects with null indexPaths

為{幸葍}努か 提交于 2019-12-03 03:55:37
jasonfu

Have you tried to use NSFetchedResultsController in Memory-Only-tracking mode? (Memory-only tracking: the delegate is non-nil and the file cache name is set to nil)

This can be bypassed by using -[NSFetchedResultsController fetchedObjects] objectAtIndex:]

codepadawan

I suppose I'd be silly to point out that NSLog(@"%@",indexPath) will always return null?

You need to do

NSLog(@"section %i",(int)indexPath.section);
NSLog(@"row %i",(int)indexPath.row);

Don't you?

Look at the sortDescriptors order of fetchedResultsController. Section key field must first sortDescriptor in order.

If fetchedResultsController have more than one sortDescriptor and first descriptor isn't section key field than indexPathForObject: method couldn't resolve indexPath.

What does the creation of the NSFetchedResultsController look like?

Update

FYI, you can update your question with the code instead of using PasteBin.

Are you using multiple threads in this code anywhere to access the NSFetchedResultsController?

I copied and pasted your code into the default Core Data navigation template, altered the entity to Reminder with a string attribute of textContent and it ran fine. There is nothing wrong with this code or the setup of the fetched results controller.

I think that the problem is actually with either your Reminder entity, the Reminder class or the textContent attribute or object. These errors could be caused by not being able to properly process the Reminder objects.


Edit:

Make sure you only run this test after some objects have been added to the context. It will crash if there are no objects. I'll test with a window-based template.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!