IKImageBrowserView“--ImageKit 错误:在非主线程中调用了 reloadData”

发布于 2024-10-10 19:24:44 字数 424 浏览 8 评论 0原文

我正在编写一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

a√萤火虫的光℡ 2024-10-17 19:24:44

** 已修复 **

原因是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文