Reputation: 2094
I have a UITableView with lots of UIButton. Large local images displayed in buttons. I use this code to load large image async(UIButton's category):
- (void)asyncLoadImageAtPath:(NSString *)fullPath forState:(UIControlState)state
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *image = [[UIImage alloc] initWithContentsOfFile:fullPath];
dispatch_async(dispatch_get_main_queue(), ^{
[self setImage:image forState:state];
});
});
}
initWithContentsOfFile: running in other thread, while update UI by setImage:forState: in main thread. But setImage:forState: costs too much time, it makes UITableView scroll not smoothly.
So is there any way to update UIImageView or UIButton's UI async?
Special thanks!
Upvotes: 0
Views: 283
Reputation: 53301
For async images I use AsyncImageView, it works fine on tableViews
Upvotes: 1
Reputation: 1658
check out the SDWebImage, This library provides a category for UIImageVIew with support for remote images coming from the web.
Upvotes: 1