Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在加载视图之前从iCloud加载文档_Ios_Multithreading_Icloud_Uidocument - Fatal编程技术网

Ios 在加载视图之前从iCloud加载文档

Ios 在加载视图之前从iCloud加载文档,ios,multithreading,icloud,uidocument,Ios,Multithreading,Icloud,Uidocument,我在iCloud上有图像,我为它们将UIDocument子类化。现在我想在加载ViewController后在UITableView上显示图像。因此,我在viewDidLoad方法中添加了此代码 - (void)viewDidLoad { ... iCloudImage *iClImage = [[iCloudImage alloc] initWithFileURL:ubiquitousPackage]; [

我在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?

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

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