第一次加载时 SDWebImage 单元格图像视图大小错误

SDWebImage cell image view size wrong on first load

首次加载 table 细胞图像时,图像为 "squished":

如果我点击后退按钮,然后继续前进,它会刷新并且看起来不错:

知道为什么会这样吗?它与我的占位符图像大小或某种方式有关吗?我只是想不出它会是什么。

视图控制器:

- (NSURL *)image {
    NSString *string = [NSString stringWithFormat:@"%@", self.details[@"image"]];
    NSURL *url = [NSURL URLWithString:string];
    return url;
}

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

    // Configure the cell...
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = [self name];
            cell.detailTextLabel.text = @"Name";
            break;
        case 1:
            cell.textLabel.text = [self email];
            cell.detailTextLabel.text = @"Email";
            break;
        case 2:
            cell.textLabel.text = [self phone];
            cell.detailTextLabel.text = @"Phone";
            break;
        case 3:
            cell.textLabel.text = @"Img";
            break;
        default:
            break;
    }
    [cell.imageView sd_setImageWithURL:[self image]
                      placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                             completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                 // ... completion code here ...
                                 NSLog(@"Loaded: %@", image);
                             }];

    return cell;
}

试试这个:

cell.imageView.contentMode = UIViewContentModeScaleAspectFit;