开发者

How to preload images in a separate thread but use them in UIImageView?

开发者 https://www.devze.com 2022-12-09 00:30 出处:网络
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 开发者

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 开发者_如何学JAVAin the main thread then?


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];

0

精彩评论

暂无评论...
验证码 换一张
取 消