views:

79

answers:

1

AFAIK, a thread can not access UI components. But I want to preload images in a background thread and then display these in an UIImageView. Do I have to use special methods to access UIImageView in the main thread then?

+1  A: 

If I understood your question correctly, you're half correct. Threads can access UI components, but only the main thread can do it reliably. Your background thread can use performSelectorOnMainThread:withObject:waitUntilDone: to call up selectors in the main thread, and from those selectors interact with the UI.

Example:

[self performSelectorOnMainThread:@selector(updateImage) withObject:nil waitUntilDone:YES];

zenzelezz
what would waitUntilDone do?
HelloMoon
waitUntilDone specifies whether or not the calling thread will block (halt execution) until the selector has finished running.
zenzelezz