【发布时间】:2017-09-05 16:56:59
【问题描述】:
我在使用 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;
这是我的 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"]];
}
}
现在,问题是如果我在某些图像完成加载之前向下滚动。例如,假设我看到前 8 行,并且第 1、2 和 3 行仍在加载它们的图像,现在我滚动到 9-16,我看到所有它们的 defaultAvatar,几秒钟后(我猜测当第 1,2 和 3 行的图像完成下载时),第 9、10 和 11 单元格上的图像将更改为属于 1,2 和 3 的图像。
我不知道当我重复使用单元格时是否有办法阻止图像下载,或者类似的东西。
谢谢你,对不起我的英语!
【问题讨论】:
-
是 cell.userImage 还是只是 userImage?
-
loadFromDictionary 是 cell.userDetailsView 的一个方法,是自定义的 UserDetailsTableViewCell 里面的自定义视图。在那个 loadFromDictionary 方法里面只有 userImage。
-
啊哈我现在明白了,我也很高兴你找到了解决方案。
标签: ios uitableview sdwebimage