2012-06-08 43 views
0

我有iCloud上的圖像和我subclassed UIDocument他們。現在我想在ViewController加載後在UITableView上顯示圖像。因此,我增加這個代碼viewDidLoad方法內加載文件從iCloud視圖之前將被加載

- (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?

回答

2

我最近有同樣的問題。我沒有等到加載視圖,直到下載圖像,而是在表格上顯示進度指示器。然後,當圖像加載時,我向視圖發送了NSNotification,通知它刪除進度指示器並加載數據。

這樣,您可以保持UI的響應,並顯示用戶正在加載的內容。如果您需要我進一步瞭解技術細節,請告訴我。

相關問題