2013-03-14 42 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