XCode 4.5.2;我正在从这样的远程服务器下载图像:
- (void)viewDidLoad
{
[super viewDidLoad];
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage)
object:nil];
[queue addOperation:operation];
}
- (void)loadImage{
self.theobject = [RemoteQuery loadObjectWithImage:self.imageKey];
[self performSelectorOnMainThread:@selector(displayImage) withObject:nil waitUntilDone:YES];
}
-(void)displayImage{
UIImage *image = [UIImage imageWithData: self.theobject.imageData];
[self.imageView setImage:image];
}
这在 IOS 模拟器上运行良好,但在设备上不起作用;似乎在从 [RemoteQuery loadImage] 加载数据之前调用了 displayImage。在显示之前确保图像已正确加载的最佳方法是什么?