Dem*_*dus 9 uitableview ios sdwebimage
我有一个问题,使用SDWebImage将图像加载到自定义UITableViewCell内的UIImageView.这是我在UITableView委托中的代码:
static NSString *userTableId = @"userTableId";
UserDetailsTableViewCell *cell = (UserDetailsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:userTableId];
NSDictionary *user = [userList objectAtIndex:indexPath.row];
NSInteger position = indexPath.row + 1;
[cell.userDetailsView loadFromDictionary:user WithIndex:position ForCharitie:false];
cell.userDetailsView.delegate = self;
cell.userDetailsView.delegate = self;
return cell;
Run Code Online (Sandbox Code Playgroud)
这是我的loadFromDictionary代码:
-(void) loadFromDictionary: (NSDictionary *) dic WithIndex: (NSInteger) index ForCharitie: (BOOL) isCharitie{
NSDictionary *userImageDic = [dic objectForKey:@"image"];
NSString *url =[userImageDic objectForKey:@"url"];
[userImage setImage:[UIImage imageNamed:@"defaultAvatar"]];
if ([url class] != [NSNull class]){
[userImage setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"defaultAvatar"]];
}
}
Run Code Online (Sandbox Code Playgroud)
现在,问题是如果我在一些图像完成加载之前向下滚动.例如,假设我看到前8行,第1,2和3行仍然加载他们的图像,现在我滚动到9-16,我看到了defaultAvatar所有这些,并在几秒后(我猜图像时)第1,2和3行完成下载),单元格9,10和11上的图像变为属于1,2和3的图像.我不知道是否有办法阻止图像下载时我重用了这个细胞,或类似的东西.谢谢你,对不起我的英文!
Mic*_*ann 16
如果您在表上设置了UITableViewDelegate,则可以使用委托方法:
- tableView:didEndDisplayingCell:forRowAtIndexPath:
当单元格滚出屏幕时,将图像设置为NULL(或默认值).
由于您正在使用SDWebImage,因此在单元格的图像视图中取消它可能就像" cancelCurrentImageLoad"一样简单.
| 归档时间: |
|
| 查看次数: |
4126 次 |
| 最近记录: |