【发布时间】:2012-09-05 06:48:32
【问题描述】:
在我的 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];
【问题讨论】:
-
为什么伙计们,你们对问题的评分降低了?
-
我没有投反对票,但我怀疑这是缺乏信息。 “它不起作用”不是很有诊断意义。
标签: iphone ios xcode multitasking