2013-03-12 47 views
0

在mu UITable视图中,我显示来自服务器的图像..为此我使用延迟加载。 我可以在屏幕上显示行时加载图像。如何增加加载的图像数量。如何在Lazy Loading上加载更多图像

像 - 首次有3个表格单元格可见,并且这些单元格上的图像会以2秒的延迟加载。如何在同一时间将下一行加载图像?

我使用下面的函数为什么要使用此代码加载图像

- (void)loadImagesForOnscreenRows 
    { 
    if ([imageArray count] > 0) 
    { 
    NSArray *visiblePaths = [tableView indexPathsForVisibleRows]; 
    for (NSIndexPath *indexPath in visiblePaths) 
    { 
     AppRecord *appRecord = [dataArray objectAtIndex:indexPath.row]; 

     if (!appRecord.appIcon) // avoiding the imagen download if already has an image 
     { 
      [self startIconDownload:appRecord forIndexPath:indexPath]; 
      } 
     } 
     } 
    } 
+1

为什么不使用SDWebImage https://github.com/rs/SDWebImage – BhushanVU 2013-03-12 08:46:52

+0

使用SDWebImage。它的vey快速和易于使用的图像在桌面视图 – 2013-03-12 09:18:08

+0

我已经下载,但没有在我的xcode工作 – 2013-03-12 09:19:29

回答

-1

你可以改变以下键值,它只是完全符合联合国有限的影像工作。

kIDStr  = @"id"; 
kNameStr = @"im:name"; 
kImageStr = @"im:image"; 
kArtistStr = @"im:artist"; 
kEntryStr = @"entry"; 
0

自己的方式做事情

你可以做到这一点通过在后台下载图像和当他们这样做饰面,您可以发布NSNotification的方法重新加载tableView。但在下载图像时,您必须向用户显示加载视图或其他内容,以告诉他图像正在下载。

建议

我不建议你,最好的办法就是与SDWebImage独立下载他们每个人的背景,也使您的tableView的更快的响应。当图像被下载您展示一个默认的图像(占位符),图像被下载后,该功能将其设置在那里它需要:

你只需要#import <SDWebImage/UIImageView+WebCache.h>到你的项目,你也可以定义占位符,当图像被与眼前这个代码下载:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     static NSString *CellIdentifier; 
     CustomCell *cell = [tableview dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

     MyObject *object = (MyObject *)[self.list.array objectAtIndex:indexPath.row]; 

     //Here is where you set your image URL and it's placeholder 
     [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] 
         placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

     return cell; 
} 

它还缓存下载的图像,并为您提供一流的性能。