开发者

NSFetchedResultsController for same managed object (table)

开发者 https://www.devze.com 2023-01-15 15:29 出处:网络
I would like to know if I can do this VIEW 1: use NSFetchedResultsController on TABLEA to retrieve the data, display in a table view and take actions to save it

I would like to know if I can do this

VIEW 1: use NSFetchedResultsController on TABLEA to retrieve the data, display in a table view and take actions to save it

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:referringObject sectionNameKeyPath:nil cacheName:@"TABLEA"];

and then in VIEW 2 use NSFetchedResultsController on the SAME table i.e. TABLEA to retrieve the data without table view and go back 开发者_如何学Goto VIEW 1 to save that previous managed object ??


TABLEA is not an SQL table. Core Data is not SQL. In this case, TABLEA is just the fetched results controller's (FRC) cache file. Passing the same cache between controllers would do nothing because as soon as you changed anything, the cache would refresh itself anyway. You can in principle pass the FRC itself but this is never done because it gets messy.

Managed object instances are attached to managed object contexts and not to fetches or fetched results controller. If you want to pass a managed object between view controllers you pass the object itself. If you want to save the context in different controllers then you pass the context as well. The fetches don't enter into it.

Fetches/FRC are usually specific to a particular view-controller because each view-controller needs to display a specific subset of data in a specific sort order so each view-controller needs to customize its own fetch.


They will return the same managed objects provided you use the same managed object context.

0

精彩评论

暂无评论...
验证码 换一张
取 消