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

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

问题描述

所以我习惯于iOS开发,所以我很高兴与NSFetchedResultsController。但是,这不存在于Mac OS X环境中。我知道我可以使用NSArrayController作为替代。我可能会使用这个类可怕的错,但它工作到现在。
我初始化NSArrayController如下:

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

NSError * error = nil;
[newConversationsController fetchWithRequest:nil merge:NO er​​ror:& error];
NSCAssert(!error,error.description);然后我听NSManagedObjectContext的更改,并抓取并重新加载NSTableView如下:



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

[self.tableView reloadData];

正如我前面提到的,我可能使用这个完全错误,但我不喜欢使用绑定。
现在到实际问题:应用程序的另一个类可能删除NSArrayController保存的NSManagedObject。 NSArrayController立即释放这个被删除的对象,使我不可能弄清楚哪个对象是。最后的目标是知道什么对象在什么索引被删除,所以我可以动画的NSTableView的行。



我希望它清楚我的目标。
感谢任何帮助

解决方案

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

BUT NSArrayController是一个很接近的匹配!它还获取和排序CoreData实体。



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






例如请参阅:



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


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

解决方案

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

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

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