NSArrayController rearrangeObjects错误 [英] NSArrayController rearrangeObjects error

查看:168
本文介绍了NSArrayController rearrangeObjects错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦与NSArrayController rearrangeObjects函数 - 这个函数调用从一些背景踏板和有时应用程序崩溃与错误:'endUpdates调用没有beginUpdates'。

I have troubles with NSArrayController rearrangeObjects function - this function called from some background treads and sometimes App crashes with error: 'endUpdates called without a beginUpdates'.

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

How can i detect if arrayController is rearranging objects in current moment and add next rearrange to some like queue or cancel current rearranging and run new?

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

May be there is another solution for this problem?

添加编辑代码

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

Don't do that. AppKit (to which NSArrayController belongs) is not generally thread safe. Instead, use -performSelectorOnMainThread:... to update your UI (including NSArrayController). ALWAYS do updating on the main thread.

这篇关于NSArrayController rearrangeObjects错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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