我遇到了在应用程序中加载内容的问题,我发现应用程序提取了数据,但图像需要大量时间加载,是否有加载的可能性图像后缀。代码如下:由于图像加载问题导致应用程序放慢
NSDictionary *dict=[discussionArray objectAtIndex:indexPath.row];
UIImageView *avatarimage = (UIImageView *)[cell viewWithTag:4];
NSString *photoStrn=[dict objectForKey:@"photo"];
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSString *u=[NSString stringWithFormat:@"http://%@",photoStrn];
NSURL *imageURL=[NSURL URLWithString:u];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
dispatch_sync(dispatch_get_main_queue(), ^{
UIImage *dpImage = [UIImage imageWithData:imageData];
if (dpImage==nil)
{
dpImage = [UIImage imageNamed:@"profileImage.png"];
}
avatarimage.image = dpImage;
});
如果您想了解更多的细节,我会提供:)
看到这样一个http://stackoverflow.com/questions/9786018/loading-an-image-into-uiimage-asynchronously – Balu 2013-03-14 11:02:16
看看这一个回答:http://stackoverflow.com/a/15270523/2106940 – Jeremy 2013-03-14 11:04:15