2015-10-05 58 views
0
NSDictionary* dict2 = AppDelegate_Object.MyAssociates[indexPath.row]; 
NSURL* url   = [NSURL URLWithString:dict2[@"Bcode"]]; 
NSURLRequest* request = [NSURLRequest requestWithURL:url]; 

[NSURLConnection sendAsynchronousRequest:request 
              queue:[NSOperationQueue mainQueue] 
           completionHandler:^(NSURLResponse * response, 
                NSData * data, 
                NSError * error) { 
            if (!error){ 
             UIImage *image = [[UIImage alloc] initWithData:data]; 
            cell.ImageVc.image=image; 
            } 

           }]; 

我在cellForRowAtIndexPath中使用這段代碼來顯示圖像,但是當我滾動表格圖像時,我改變了什麼是做錯了。請幫幫我???cellForRowAtIndexPath方法數據變化

+0

您每次在視圖上出現新的單元格時都會調用URL。每次你滾動,URL被調用。 –

+0

@ Mr.T如何解決這個bug請告訴我 –

+0

這不應該是一個問題,無論如何你都稱之爲異步。網址返回什麼? –

回答

0

讓我看看你的代碼中發生了什麼。讓我們說你有排在你的tableview A,B,C和d,當你要下載行A的圖像,因爲它是異步調用,然後您滾動表視圖.... 行A交換行B行C行D。作爲輸出,圖像行A,可以顯示在行B行C行D

要解決此問題,您必須持有imageview的參考資料,或者在下載圖像後在運行時獲取該圖像視圖的參考資料。

+0

先生,如何舉辦imageview的參考,並得到它請請解釋我 –

+0

@LCNagar你可以使用創建imageview cateogry,那裏你可以實現異步調用。 – SachinVsSachin