Search code examples
cocoareloaddataimagekitikimagebrowserview

IKImageBrowserView "--ImageKit Error: reloadData called in non main thread"


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?


Solution

  • ** 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.