开发者

asynchronous UIImageView in custom UITableViewCell

开发者 https://www.devze.com 2023-04-09 19:03 出处:网络
I would like to know how people implement an asynchronous UIImageView loading, if you have it inside a custom UITableViewCell, I\'ve seen quite some examples using GCD, subclassing UIImageView.. all o

I would like to know how people implement an asynchronous UIImageView loading, if you have it inside a custom UITableViewCell, I've seen quite some examples using GCD, subclassing UIImageView.. all of them must involves NSURLRequest and NSURLConnec开发者_如何转开发tion. So how do people do this in a subclass of UITableViewCell that has an UIImageView in it?


Look at this category: SDWebImage. It's a image downloader for UIImageView. You place you're image view in your cell, and in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method, just use:

[myImageView setImageWithURL:[NSURL URLWithString:@"example.com/myimage.jpg"]];


Here is a very good tutorial which explains asynchronous loading in general....

http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

You can use the same idea to load your image view..


I think the simple and ideal way to do this is to do the following steps

  1. Inside cellForRowAtIndexPath: check if the image is available locally load it, else fire off nsurl request to download it in a separate thread and show a loading indicator image.
  2. On completion of request thread, store the image locally reload tableView.
0

精彩评论

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