Using an NSFetchedResultsController without a UITableViewController

孤街醉人 提交于 2019-12-04 10:04:48
robenkleene

This is solved by using -[NSFetchedResultsController fetchedObjects] objectAtIndex:]

NSFetchedResultsController behaves as a collection of managed objects, similar to an NSArray, which makes it easy to use. In fact, it exposes a read-only property called fetchedObjects that is of type NSArray to make things even easier to access the objects it fetches.

Is there anything wrong with working with -[NSFetchedResultsController fetchedObjects]? I'm not quite sure what you mean when you say you running into problems creating new pointers and retaining them--could you explain more? You shouldn't usually have to retain NSManagedObjects (they're fetched and faulted as needed), so that might be the issue.

(Note this is a simplification of the issue, in some circumstances the objects do have IndexPaths, but I've encountered enough problems to believe that expecting IndexPaths without a UITableViewController is a bad idea.)

Both UITableView and NSFetchedResultsController use the NSIndexPath UIKit Additions extensions to NSIndexPath. That extended class generates indexPaths with explicit section and row attribute. These paths should be manually created using:

+[NSIndexPath indexPathForRow:inSection:]

If you use other methods to create the indexPath, the receivers have to infer the section and row attributes. They will usually infer correctly but the possibility of error remains.

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