ios - 首次加载时 SDWebImage 单元格 ImageView 大小错误

标签 ios objective-c uitableview imageview sdwebimage

在第一次加载表格单元格图像时,图像被“压扁”:

enter image description here

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

enter image description here

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

查看 Controller :

- (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;

关于ios - 首次加载时 SDWebImage 单元格 ImageView 大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38483418/

相关文章:

iOS - 字符串错误

objective-c - 当我将 OS X 升级到 10.9 时,我的 applescript 不再工作

ios - UITableViewCell 内的 UICollectionView

ios - 在 iOS 上重新加载 UITableview

ios - 切换 ViewController 时的 UISwitch/UISlider 值

ios - 将 UITableViewCell 引用传递给其他 VC 使其消失

ios - 函数返回一个空数组而不是填充它

ios - 如何在 iOS 中为多个动态按钮和标签设置自动布局?

ios - xcodebuild 错误 : "requested but didn' t find extension point with identifier . ..”

ios - Xcode 将我的框架导入项目