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

如何检测arrayController当前是否正在重新排列对象,然后将下一个重新排列添加到队列中,或者取消当前重新排列并运行new?

可能有针对此问题的另一种解决方案?

编辑代码已添加:

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)。总是在主线程上进行更新。

10-05 19:34