Don't try to reinvent the wheel. You should use an external library to do that, there are some great examples. Take a look at SDWebImage, it does exactly what you want.
Using it, you can forget queues, manually caching... Just import the header:
#import <SDWebImage/UIImageView+WebCache.h>
and, in your tableView:cellForRowAtIndexPath:
method, you can just set the image into the UIImageView
with the setImageWithURL:
(or any of its variants: with placeholders, etc.) method provided by the library:
NSString* imageURL = [[tableData objectAtIndex:indexPath.row] valueForKey:@"picture"];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL]];
That's all. The library takes care of everything for you. If you want to somehow manage the cache behind this and configure it, you can, using the SDWebImageManager
class (more info in the GitHub page).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…