图像仅在滚动UITableView后更新
我有一个水平滚动表视图。每个单元格占据整个屏幕以显示完整的图片。我正在偷懒地加载图片。我遇到的问题是,图片下载完成后,单元格中的UIImageview.image不会自动更新。我需要滚动到另一个单元格并返回以显示它。 以下是图片下载完成后调用的方法:图像仅在滚动UITableView后更新,uitableview,uiimageview,lazy-loading,Uitableview,Uiimageview,Lazy Loading,我有一个水平滚动表视图。每个单元格占据整个屏幕以显示完整的图片。我正在偷懒地加载图片。我遇到的问题是,图片下载完成后,单元格中的UIImageview.image不会自动更新。我需要滚动到另一个单元格并返回以显示它。 以下是图片下载完成后调用的方法: - (void)imageDownloaderDidFinish:(PictureDownloadOperation *)downloader { NSLog(@"image download finished");
- (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];
}
这是CellForWoeAtinex路径:
- (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;
}
谢谢
更新:
有关此问题的更多信息。排除故障后,我发现问题出在重载rowsatindexpaths上。它不会为要加载的图像调用cellForRowAtIndexPath。但是我仍然不确定它是否调用cellforrowatinexpath。我也尝试过[tableview reloadData],但没有成功
修正了它:
通过在此现有表视图中添加另一个表视图,该问题已得到修复。我以前的方式是UIView中的UITableView。我修改了它,所以我有一个带有一个单元格的UITableView。创建了一个自定义单元格,并在该单元格中添加了另一个表,这样我就可以水平滚动它,并使用imageview为水平tableview添加了另一个自定义单元格。这就成功了