【发布时间】:2014-08-28 06:45:36
【问题描述】:
以下代码用于我的tableView:cellForRowAtIndexPath 方法。
我使用 AFNetworking 的setImageWithURLRequest 来显示单元格的图像。
但是,有时会在我的 tableView 中的单元格上放置错误的图像。
我认为错误是触发成功块并且contact 对象不再对应于下载的图像。
// ... init/deque ...
/* CAN BE EITHER USER OR CONTACT DETAILS */
id contact = [[self.connections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
if ([contact isKindOfClass:[User class]]) {
[cell configurateCellWithUser:(User *)contact];
if(((User*)contact).avatar_name.length > 0){
[cell.profilePicture setImageWithURLRequest:[self getURLRequestForUser:contact]
placeholderImage:[UIImage imageWithData:((User*)contact).avatar_image]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
cell.profilePicture.image = image;
((User*)contact).avatar_image = UIImageJPEGRepresentation(image, 0.01);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
cell.profilePicture.image = [UIImage imageNamed:@"avatar_contact-card"];
}];
}else {
[cell.profilePicture setImage:[UIImage imageNamed:@"avatar_contact-card"]];
}
} else {
[cell.profilePicture setImage:[UIImage imageNamed:@"avatar_contact-card"]];
[cell configurateCellWithContactDetails:(ContactDetails *)contact];
}
return cell;
如何解决此问题并为正确的单元格显示适当的图像?
【问题讨论】:
标签: ios objective-c uitableview afnetworking