Reputation: 87141
I have UITableViewController with a basic cell. In my tableView: cellForRowAtIndexPath:
method implementation I set the .imageView
property of my cell to get the data from the Internet, using AFNetworking 2.0 category: UIImageView+AFNetworking.
if (p.avatarPhoto) {
[cell.imageView setImageWithURL:p.avatarPhoto placeholderImage:[UIImage imageNamed:@"photo_frame.png"]];
}
When I do it, my table rows are properly generated and image is displayed, however its size changes when I highlight the row or scroll (so the rows reappear), like on this screen capture: https://dl.dropboxusercontent.com/u/51630060/ScreenDemo-20131219-102840.mov
When I set the image to some bundled one, not one from the network, it works OK.
How should I set the image to have it working properly?
EDIT: The image I'm using for testing is this one: http://hollywoodvideo.com/wp-content/uploads/2013/08/avatar-whatshisface.jpg. Maybe it's the matter of the aspect ratio of this image?
Upvotes: 1
Views: 209
Reputation: 25459
I had very similar issue with AFNetworking 1 and I sorted it by create week reference to the cell and by called setNeedsDisplay. Please see belowe, it's AFNetworking 1 byt you can make it works for AFN.. 2.o:
__weak UITableViewCell *weakCell = cell;
[cell.imageView setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:p.avatarPhoto]
placeholderImage:[UIImage imageNamed:@"photo_frame.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
weakCell.imageView.image = image;
[weakCell setNeedsLayout];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
}];
Upvotes: 1