我在使用 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/