2017-02-24 94 views
0

這裏是我的代碼來顯示從URL的tableview單元格中的圖像。圖像顯示在URL從UITableviewCell

cell1.tag = indexPath.row; 

    dispatch_queue_t Queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 
    dispatch_async(Queue, ^(void){ 

     NSData * imgData=[NSData dataWithContentsOfURL:[NSURL URLWithString:images[indexPath.row]]]; 

     UIImage* image = [UIImage imageWithData:imgData]; 
     if (image) { 
      dispatch_sync(dispatch_get_main_queue(), ^{ 
       if (cell1.tag == indexPath.row) { 
        cell1.img.image = image; 
        [cell1 setNeedsLayout]; 
       } 
      }); 
     } 

    }); 

使用此我得到的圖像,但不是同步的方式。 如何同步下載圖像?

+0

此處粘貼圖片全圖url – kb920

+0

http://is1.mzstatic.com/image/thumb/Music30/v4/9a/40/23/9a402364-cb4e-9922-7125-4d49b24faacb/rm_image.jpg/170x170bb- 85.jpg @ kb920 –

+0

即使在異步調度塊中,使用'dataWithContents ...'從遠程URL加載數據*同步*總是一個壞主意。 – vadian

回答

0

兩個選項:

1),你需要在方法的最後返回細胞,或

2)去莢命名爲:翠鳥。你會在github上找到它。

+0

它的swift庫...我正在使用objective-c。 –

+0

去哈內克https://github.com/Haneke/Haneke –

+0

好的..謝謝 –

相關問題