cocoa - NSArrayController 重新排列对象错误

标签 cocoa nsarraycontroller

我在使用 NSArrayController rearrangeObjects 函数时遇到了麻烦 - 该函数是从某些后台步骤调用的,有时应用程序会因错误而崩溃:“endUpdates 在没有 beginUpdates 的情况下调用”。

我如何检测 arrayController 是否在当前时刻重新排列对象并将下一个重新排列添加到队列等对象中或取消当前重新排列并运行新的?

这个问题可能还有其他解决方案吗?

编辑添加的代码:

TableController implementation:

- (void)setContent{//perfoms on main thread
     //making array of content and other functions for setting-up content of table
     //...
     //arrayController contains objects of MyNode class
     //...
     //end of setting up. Call rearrangeObjects
     [arrayController rearrangeObjects];
}

- (void)updateItem:(MyNode *)sender WithValue:(id)someValue ForKey:(NSString *)key{
     [sender setValue:someValue forKey:key];
     [arrayController rearrangeObjects];//exception thrown here
}

MyNode implementation:

- (void)notifySelector:(NSNotification *)notify{
     //Getted after some processing finished
     id someValue = [notify.userInfo objectForKey:@"observedKey"];
     [delegate updateItem:self WithValue:someValue ForKey:@"observedKey"];
}

最佳答案

不要那样做。 AppKit(NSArrayController 所属)通常不是线程安全的。相反,请使用 -performSelectorOnMainThread:... 更新您的 UI(包括 NSArrayController)。始终在主线程上进行更新。

关于cocoa - NSArrayController 重新排列对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12094894/

相关文章:

cocoa - 如何将数组 Controller 的 'remove' 与集合运算符绑定(bind)为内容

swift - Swift 中基于 View 的表绑定(bind)

objective-c - 如何获取 NSOutlineView 可见行的索引?

cocoa - 寻求一个使用 AutoLayout 的简单 Mac OS NSTextView 示例

objective-c - 如何确定 Cocoa (OS X) 应用程序启动时间

cocoa - NSTableView 按 "space"选择行

cocoa - NSU整数转int

macos - NSArrayController 更改其选择 : what is the best way to catch this event?

cocoa - 带有 NSSearchField 的 Laggy 接口(interface)通过绑定(bind)连接到 NSArrayController