【发布时间】:2014-12-18 09:30:15
【问题描述】:
我有一个表格视图,每个单元格都有自己的图像视图。我正在使用 AsyncImageView 将来自 Internet 的图像加载到 imageview 中。某些图像视图似乎将重复的图像加载到不同的单元格中:
在上面的屏幕截图中,图片 B 在不应该加载的情况下加载了两次。当我上下滚动时,这种情况经常发生。发生这种情况时,我滚动并滚动回单元格并加载正确的图像。后来当我再次滚动时,同样的问题发生了。我无法追踪问题的来源。有人有想法么?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleTableIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}else
{
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.logoImageView];
cell.logoImageView.image = nil;
}
//Cause sections
NSMutableArray *tempArray = [self.sectionArray objectAtIndex:indexPath.section];
MyObject *myObject = [tempArray objectAtIndex:indexPath.row];
NSString *thumbUrlString = [myObject valueForKey:@"thumbUrl"];
if([thumbUrlString length]>0 )
{
NSString *imageUrl= [NSString stringWithFormat:@"http://www.sitename.com/%@",thumbUrlString];
NSURL *url = [NSURL URLWithString:imageUrl];
cell.logoImageView.imageURL=url;
}else{
cell.logoImageView.image = [UIImage imageNamed:@"placeholder.png"];
}
return cell;
}
【问题讨论】:
标签: xcode uitableview tableview asyncimageview