2013-03-14 39 views
1

我必須在tableview中顯示圖像,我得到的所有圖像,但它不顯示。這裏Array包含3個圖像,這些圖像來自服務器。當在indexpath處的行的單元格調用時,它只顯示第三個圖像,即最後一個圖像第一行和第二行將是空白的,但是當它從下到上滾動我的tableview時,不僅僅顯示第1和第2圖像。在TableView UIImageview

-

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = nil; 
    static NSString *CellIdentifier = @"Cell"; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    cell.selectionStyle = UITableViewCellSeparatorStyleNone; 
    cell.backgroundColor = [UIColor clearColor]; 
    if (appDelegate.array_xml != (id)[NSNull null]) 
    { 
     ObjMore = [appDelegate.array_xml objectAtIndex:indexPath.row]; 

     //imageview 
     NSString *str_img = ObjMore.iconurl; 
     str_img = [str_img stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
     NSLog(@"str_img: %@", str_img); 

     self.imageicon = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)]; 
     NSURL *url = [NSURL URLWithString:str_img]; 
     NSLog(@"url %@",url); 
     [[AsyncImageLoader sharedLoader]cancelLoadingURL:url]; 
     self.imageicon.imageURL = url; 
     self.imageicon.userInteractionEnabled = YES; 
     self.imageicon.tag = indexPath.row; 
     self.imageicon.backgroundColor = [UIColor clearColor]; 
     [cell.contentView addSubview:self.imageicon]; 

} 
     return cell; 
} 

請幫助。 在此先感謝。

+0

不,我不是取消URL裝載因爲像我也必須顯示文本和我得到的所有三個文本,但在圖像 – Abha 2013-03-14 05:17:18

回答

2

請改變你的代碼 -

[AsyncImageLoader sharedLoader] cancelLoadingURL:self.imageicon.imageURL]。

+0

感謝凱蒂,它的工作.. :) – Abha 2013-03-14 05:32:27

0

您是否在刷新imageview或重新加載表格行後得到圖像?

此外請確保您正在刷新主線程中的用戶界面。

+0

唯一有問題沒有,我不是刷新桌子。 – Abha 2013-03-14 05:21:10

+0

當你從URL獲取圖像時,你是否將圖像設置爲imageview? – 2013-03-14 05:25:30

+0

對不起,網址將被取消。我剛剛檢查過它。 – Abha 2013-03-14 05:29:53

2

我建議你使用這個AsyncImageView。我已經使用它,它創造奇蹟。要調用此API:

ASyncImage *img_EventImag = alloc with frame; 
NSURL *url = yourPhotoPath; 
[img_EventImage loadImageFromURL:photoPath]; 
[self.view addSubView:img_EventImage]; // In your case you'll add in your TableViewCell. 

與使用UIImageView相同。簡單,它爲你做大部分事情。 AsyncImageView在UIImageView中同時包含一個簡單的類別,用於在iOS上異步加載和顯示圖像,以便它們不鎖定UI,以及用於更高級功能的UIImageView子類。 AsyncImageView適用於URL,因此可以與本地或遠程文件一起使用。

加載/下載的圖像緩存在內存中,並在發生內存警告時自動清除。 AsyncImageView獨立於UIImage緩存運行,但默認情況下,位於應用程序捆綁包根目錄中的任何圖像都將存儲在UIImage緩存中,以避免重複緩存圖像。

該庫還可用於獨立於UIImageView加載和緩存圖像,因爲它提供對底層加載和緩存類的直接訪問。

1

創建對象AsyncImageView代替的UIImageView