d4n*_*1k3 1 iphone url image uitableview nsmutabledictionary
编辑:在阅读下面的答案并查看我现在丢失的所有指南后,我太过于努力想出来了.
我不想为我完成编码,我需要一些明确的建议,如何设置一个单独的线程,然后将其引用到我的tableView.
NOOB的任何教程?!?
这是我为将图像放入tableView而设置的代码.所有图像都会加载,但只有在滚动表格时才会加载.
怎么能停止?
任何帮助,将不胜感激.
NSString *userImage = [(Tweet*)[profile objectAtIndex:indexPath.row] profileImage];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[(Tweet*)[profile objectAtIndex:indexPath.row] profileImage]]];
dict =[[NSMutableDictionary alloc]init];
//UIImage *retImage =[dict objectForKey:(@"%@", userImage)];
UIImage *retImage =[dict objectForKey:userImage];
dispatch_async(dispatch_get_main_queue(), ^{
if (!retImage) {
UIImage *profileImage=[UIImage imageWithData:imageData];
[dict setObject:profileImage forKey:userImage];
}
UIImage *retImage2 =[dict objectForKey:userImage];
photo.image = retImage2;
[imageData release];
});
Run Code Online (Sandbox Code Playgroud)
在后台线程上加载图像是一种选择.更好的选择是使用自动处理后台线程的NSOperationQueue.
Apple也为此提供了样本.
请查看Lazy Loading Of TableViewCells
我希望它有帮助:)
编辑:如果你不知道,或者不想使用线程,那么还有另一种替代方案.看看这个: 下载图像换桌子没有线程
| 归档时间: |
|
| 查看次数: |
5414 次 |
| 最近记录: |