【问题标题】:Load document from iCloud before view will be loaded在加载视图之前从 iCloud 加载文档
【发布时间】: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


    【解决方案1】:

    我最近遇到了同样的问题。我没有等到图像下载完毕才加载视图,而是在桌子上显示了一个进度指示器。然后,当图像加载完毕后,我向视图发送了一个 NSNotification,通知它删除进度指示器并加载数据。

    这样,您可以让您的 UI 保持响应,并向用户显示实际正在加载的内容。如果您需要我提供更多技术细节,请告诉我。

    【讨论】:

      猜你喜欢
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 2013-10-13
      • 1970-01-01
      相关资源
      最近更新 更多