在第一次加载表格单元格图像时,图像被“压扁”:
如果我点击后退按钮,然后继续前进,它会刷新并且看起来很好:
知道为什么会这样吗?它是否与我的占位符图像大小或某种方式有关?我只是想不出它会是什么。
查看 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/