mathieug
mathieug

Reputation: 901

AFNetworking setImageWithURL:placeholderImage: wrong size

I have a problem when I setImageWithURL on an UIImageView into an UITableViewCell.
Here is the table view rendered. On the left before that I pressed on the UITableViewCell and on the right after that I pressed it.

UITableView before press UITableView after press

Here is my tableView:cellForRowAtIndexPath method :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"AddFriendCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSDictionary *user = self.result[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", user[@"firstname"], user[@"lastname"]];
    if (user[@"picture"]) {
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://jawbone.com/%@", user[@"picture"]]];
        [cell.imageView setImageWithURL:url placeholderImage:cell.imageView.image];
    }

    return cell;
}

Upvotes: 1

Views: 812

Answers (1)

mrosales
mrosales

Reputation: 1568

I just had a very similar problem last night. It happens because the UITableViewCell overrides the constraints on an imageview property, and for some reason has some unreliable functionality. I understand that this isn't exactly the most clear explanation as I did not ultimately figure out the exact source of the problem, but I was able to find a workaround.

The fix for me was to:

  1. Create a custom UITableViewCell
  2. Add a UIImageView (call the property something other than imageView) and title UILabel
  3. Constrain/set the frame of the UIImageView

Upvotes: 1

Related Questions