首次加载

时间:2016-07-20 14:00:35

标签: ios objective-c uitableview imageview sdwebimage

在第一次加载表格单元格图像时,图像被压缩":

enter image description here

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

enter image description here

知道为什么会这样吗?是否与我的占位符图像大小有什么关系?我无法想到它可能是什么。

查看控制器:

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

1 个答案:

答案 0 :(得分:2)

试试这个:

cell.imageView.contentMode = UIViewContentModeScaleAspectFit;