IKImageBrowserView“--ImageKit 错误:在非主线程中调用了 reloadData”
我正在编写一个使用 IKImageBrowserView 的 Cocoa Mac 应用程序。 当我调用以下内容时:
[imageBrowserView reloadData];
调试器控制台打印此内容:
--ImageKit Error: reloadData called in non main thread
我尝试将 reloadData 方法放入另一个方法中,然后调用以下内容:
[self performSelectorOnMainThread:@selector(reloadMyView) withObject:nil waitUntilDone:NO];
但我仍然遇到相同的 ImageKit 错误。有什么想法吗?
I am writing a Cocoa Mac app which uses an IKImageBrowserView.
When I call the following:
[imageBrowserView reloadData];
The Debugger Console prints this:
--ImageKit Error: reloadData called in non main thread
I have tried placing the reloadData method in another method and then calling the following:
[self performSelectorOnMainThread:@selector(reloadMyView) withObject:nil waitUntilDone:NO];
But I still get the same ImageKit Error. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
** 已修复 **
原因是使用 Bindings 从 NSArrayController 填充我的 IKImageBrowserView 以及填充更新后在其自己的 NSManagedObjectContext 上调用 save 的 NSOperation 的组合。
当 NSOperation 中的上下文保存时,我有一个通知观察器,这样我就可以将 mergeChangesFromContextDidSaveNotification 合并到我的主线程上下文中,但我需要在 MainThread 上执行此操作。 NSArrayController 将 automaticallyPreparesContent 设置为 YES,这“也注册为其托管对象上下文的观察者”。因此,当合并是从通知中执行时,这是在与 NSOperation 相同的单独线程上完成的,因此 NSArrayController 在单独的线程上再次准备其内容,然后再次在单独的线程上更新 IKImageBrowserView导致错误/警告。
** FIXED **
The reason was a combination of using Bindings to populate my IKImageBrowserView from an NSArrayController, and an NSOperation which called save on it's own NSManagedObjectContext after populating the updates.
I had an Notification Observer for when the context in the NSOperation saved so I could then mergeChangesFromContextDidSaveNotification to my main thread context, but I needed to perform this on the MainThread. The NSArrayController has automaticallyPreparesContent set to YES which "also registers as an observer of its managed object context". So as the merge was performed from the Notification this was being done on the same separate thread as the NSOperation, and as a result the NSArrayController was preparing it's content again on the separate thread, and then updating the IKImageBrowserView, again on the separate thread which was causing the error/warning.