我在应用程序中加载内容时遇到问题,我看到数据是由应用程序获取的,但图像需要很长时间才能加载,是否有可能在后文中加载图像。代码如下:
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;
});
如果您想了解更多详细信息,我将提供:)