2011-12-27 53 views
1

我有一個UIImageView試圖加載圖像,如果它不存在,我打電話下載圖像。一旦圖像被下載,NSNotification被髮送並且UIImageView.image被設置爲下載的圖像。這是行得通的,但在圖像設置爲在UIImageView中顯示後需要幾秒鐘。在圖像下載完成後,再次發送通知,因此延遲不是圖像的下載。UIImageView.image需要幾秒鐘時間通過NSNotification設置時顯示

以下是通知:

- (void)recieveImageDownloadUpdate:(NSNotification *)notification { 

if ([[item valueForKey:@"FlipBookPhotoID"] intValue] == imgView1.tag) { 
     // this loads the image if the tag on the UIImageView matches the notification update 
     imgView1.image = [Helpers getImageDownloadIfMissing:[[item valueForKey:@"PhotoName"] stringByReplacingOccurrencesOfString:@"_lg" withString:@""] withManufacturer:[item valueForKey:@"ManufacturerID"] withFlipBookID:[item valueForKey:@"FlipBookID"] withFlipBookPhotoID:[item valueForKey:@"FlipBookPhotoID"] shouldDownload:NO ]; 

    } 
} 

所有這一切都與尋呼一個UIScrollView用於啓用,如何獲取這些圖像的通知後,立即顯示。

+0

可以提供更多的細節... – Ali3n

+0

有一噸的代碼,只是想知道如果我需要調用強制屏幕更新 – Slee

回答

5

也許你沒有在主線程中設置它。所有UI工作都需要在那裏完成。

- (void)recieveImageDownloadUpdate:(NSNotification *)notification { 
    if ([[item valueForKey:@"FlipBookPhotoID"] intValue] == imgView1.tag) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      imgView1.image = [....] 
     }); 
} 

}

+0

這是它的方法,應該抓住了這一點。我的更新通知來自dispatch_async(dispatch_get_global_queue(0,0),^ {});這使我糾正了。謝謝! – Slee

相關問題