Mac OS X replacement for NSFetchedResultsController

风流意气都作罢 提交于 2019-12-06 22:41:42

问题


So I'm used to iOS development so I'm pretty happy with NSFetchedResultsController. However, this is not present in the Mac OS X environment. I know that I can use NSArrayController as a replacement. I might be using this class terribly wrong but it worked until now. I initialize the NSArrayController as follows:

NSArrayController* newConversationsController = [NSArrayController new];
newConversationsController.managedObjectContext = context;
newConversationsController.entityName = entityName;
newConversationsController.sortDescriptors = sortDescriptors;
newConversationsController.automaticallyRearrangesObjects = YES;

NSError* error = nil;
[newConversationsController fetchWithRequest:nil merge:NO error:&error];
NSCAssert(!error, error.description);

Then I listen to changes of the NSManagedObjectContext and fetch and reload the NSTableView as follows:

        [self.conversationsController fetchWithRequest:nil merge:YES error:&error];
    NSAssert(!error, error.description);

    [self.tableView reloadData];

As I previously mentioned, I might be using this totally wrong but I don't like to use bindings. Now to the actual issue: Another class of the application might delete an NSManagedObject held by the NSArrayController. The NSArrayController instantly releases this deleted object and makes it impossible for me to figure out which object that was. The final goal is to know what object at what index has been deleted so I can animate the rows of the NSTableView.

I hope it's clear what I'm aiming at. Thanks for any help


回答1:


there are no sections in a NSTableView so there is no 1:1 replacement

BUT NSArrayController is a close match! It also fetches and sorts CoreData entities.

For the UI you'd use bindings then (but of course you don't have to)


e.g. see:

http://cocoadevcentral.com/articles/000080.php



来源:https://stackoverflow.com/questions/21215619/mac-os-x-replacement-for-nsfetchedresultscontroller

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