Mac OS X 替换 NSFetchedResultsController [英] Mac OS X replacement for NSFetchedResultsController

查看:31
本文介绍了Mac OS X 替换 NSFetchedResultsController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我习惯了 iOS 开发,所以我对 NSFetchedResultsController 很满意.但是,这在 Mac OS X 环境中不存在.我知道我可以使用 NSArrayController 作为替代品.我可能在使用这个类时非常错误,但直到现在它仍然有效.我初始化 NSArrayController 如下:

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);

然后我监听 NSManagedObjectContext 的变化并获取并重新加载 NSTableView,如下所示:

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];

正如我之前提到的,我可能完全错误地使用了这个,但我不喜欢使用绑定.现在到实际问题:应用程序的另一个类可能会删除 NSArrayController 持有的 NSManagedObject.NSArrayController 立即释放这个被删除的对象,让我无法弄清楚那是哪个对象.最终目标是知道哪个索引处的哪个对象已被删除,以便我可以为 NSTableView 的行设置动画.

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

推荐答案

在 NSTableView 中没有节,所以没有 1:1 替换

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

但是 NSArrayController 是一场势均力敌的比赛!它还获取和排序 CoreData 实体.

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

对于 UI,您将使用绑定(但当然您不必)

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

例如见:

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

这篇关于Mac OS X 替换 NSFetchedResultsController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆