可能重复:
App crash on 4.0 but not on 5.0的UIImage使用dispatch_async工作模拟器(的iOS 5.1),但不上的设备(iOS 4.2的)
在我的iPhone应用程序需要下载的图像格式服务器,以便使用这段代码,但这在模拟器(iOS 5.1)上正常工作,但不在真实设备(iOS 4.2)上。请稍后再看看。
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 260, 160)];
NSURL *imageURL = [NSURL URLWithString:@"http://myImageURL.com/image.png"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
dispatch_async(dispatch_get_main_queue(), ^{
imageView.image = [UIImage imageWithData:imageData];
});
});
[self.view addSubview:imageView];
为什么家伙你下来分级的问题? – Buntylm
我没有低调,但我怀疑这是缺乏信息。 “不起作用”不是很有诊断性。 – borrrden