0

我已经使用苹果的延迟加载示例在 uitableview 中实现了图像的延迟加载。除一部分外,一切正常。最初,当我启动应用程序时,表格的可见单元格不会加载任何图像。但是当我滚动表格时,图像正在为剩余的单元格加载并被保留。但最初的可见单元格保持空白。

有人有类似的问题吗?

谁能指导我解决这个问题?

static NSString *EditCellIdentifier = @"EditCell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:EditCellIdentifier]; 
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:EditCellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
 }
for (UIView *view in cell.contentView.subviews){
    [view removeFromSuperview];
}   
    if ([listItems count]>0)       
    {    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    ListItem * item = [listItems objectAtIndex:indexPath.row];
    UIImageView *imageFrame = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,60,60)];
    [imageFrame setImage:[UIImage imageNamed:@"box.png"]];
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
      otherPath=indexPath;
        if (!item.appIcon)
        {
            if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
            {
                NSLog(@"Initial Values %@",item.imageURL); 
                if([item.imageURL length]==0){
                    imageView.image=[UIImage imageNamed:[categoriesImages objectAtIndex:self.configfId - 1]];
                }  
                else
                    [self startIconDownload:item forIndexPath:indexPath];
           }
       }
        else
        {
            imageView.image = item.appIcon;
        }
    [imageView setBackgroundColor:[UIColor blackColor]];       
    NSString * titleStr = [NSString stringWithFormat:@"%@. %@",item.rank,item.title];        
    NSLog(@"titleStr %@",titleStr);    
    CGSize size = [titleStr sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:11] constrainedToSize:CGSizeMake(12, 100) lineBreakMode:UILineBreakModeWordWrap];       
    if (size.height > 50 ) {            
        size = CGSizeMake(size.width,50.0 );            
    }        
    NSInteger height = 14;        
    if(item.title.length > 30){            
        height = 25;            
    }           
    [cell.contentView addSubview:imageView];        
    [cell.contentView addSubview:imageFrame];
}    
return cell;              
}
4

1 回答 1

0

我无法在您的代码中为您提供帮助,但我建议您使用SDWebImage延迟加载。你会在这里找到它https://github.com/rs/SDWebImage/。并且有一个很棒的教程,标题为“如何使用它”

于 2012-07-30T12:50:32.763 回答