【发布时间】:2012-06-08 11:03:31
【问题描述】:
我在 iCloud 上有图像,我为它们子类化了 UIDocument。现在我想在加载 ViewController 后在 UITableView 上显示图像。所以我在viewDidLoad 方法中添加了这段代码
- (void)viewDidLoad
{
...
iCloudImage *iClImage = [[iCloudImage alloc] initWithFileURL:ubiquitousPackage];
[iClImage openWithCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"iCloud document opened");
dataFromFileManager = [iClImage.imageDictionary objectForKey:img.fileName];
imageToDraw = [[[UIImage alloc] initWithData:dataFromFileManager] autorelease];
} else {
NSLog(@"failed opening document from iCloud");
imageToDraw = [UIImage imageNamed:@"defaultImage.jpg"];
}
[arrayOfImages addObject:imageToDraw];
}];
...
}
在这里,我将所有图像一张一张地收集到NSMutableArray *arrayOfImages 中,然后在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中使用该数组。
但是它们没有显示在表格中,因为它们正在另一个线程中下载。
如何解决该问题并仅在下载图像或设置默认图像后才开始显示 UITableView?
【问题讨论】:
标签: ios multithreading icloud uidocument