我遇到了在應用程序中加載內容的問題,我發現應用程序提取了數據,但圖像需要大量時間加載,是否有加載的可能性圖像後綴。代碼如下:由於圖像加載問題導致應用程序放慢
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