滚动UITableView后,图像才会更新

时间:2014-01-23 22:32:28

标签: uitableview uiimageview lazy-loading

我有一个水平滚动表视图。每个单元格都会在整个屏幕上显示完整的图片。我正在懒散加载图片。我遇到的问题是,当图片完成下载时,来自单元格的UIImageview.image不会自动更新。我需要滚动到另一个单元格并返回以显示它。 以下是图片下载完成时调用的方法:

    - (void)imageDownloaderDidFinish:(PictureDownloadOperation *)downloader {
           NSLog(@"image download finished");
           NSIndexPath *indexPath = downloader.indexPathInTableView;
           PictureRecord *theRecord = downloader.photoRecord;
           [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]      withRowAnimation:UITableViewRowAnimationFade];
           [self.pendingOperations.downloadsInProgress removeObjectForKey:indexPath];
    }

这是cellforwoeatindexpath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"HorizontalCell";
    HorizontalTableCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[HorizontalTableCell alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width)];
    }

cell.contentView.transform = CGAffineTransformMakeRotation(-M_PI/-2);

PictureRecord *aRecord = [self.photos objectAtIndex:indexPath.section];

[cell.indicator startAnimating];
if (aRecord.hasImage) {
    [cell.indicator stopAnimating];
    [cell.pic setImage:aRecord.image];
    [cell setNeedsDisplay];
    cell.username.text = aRecord.username;
}
else if (aRecord.isFailed)  {
    [cell.indicator stopAnimating];
    cell.pic.image = [UIImage imageNamed:@"first.png"];
}
else {
    [cell.indicator startAnimating];
    if (!myTableView.dragging && !myTableView.decelerating) {
        [self startOperationsForPhotoRecord:aRecord atIndexPath:indexPath];
    }
}

return cell;
}

由于

更新:

有关此问题的更多信息。经过故障排除后,我发现问题出在reloadRowsAtIndexPaths上。它不会调用cellForRowAtIndexPath来加载图像。但是我仍然不确定它不会调用cellForRowAtIndexPath。我也试过[tableview reloadData]而没有运气。

固定IT: 通过在此现有表视图中添加另一个tableview来解决此问题。我之前的方式是UIView中的UITableView。我修改了它,所以我有一个UITableView与一个单元格。创建了一个自定义单元格并在该单元格中添加了另一个表格,以便我可以水平滚动它并为imageview添加另一个自定义单元格用于水平tableview。这就行了。

0 个答案:

没有答案