将URL中的图像加载到uiimage中,然后将这些图像添加到uitableviewcell uiimageview中,如下面的代码。我不知道图像大小,但需要强制它们在tableviewcell图像中为40x40。图像在uitableview中以不同的宽度持续加载。当UIImage从URL加载时,在UITableViewCell中设置UIImageView大小?
通读其他与uiimage大小/缩放相关的帖子,但这些解决方案不适合我。我想这是因为我使用uitableviewcell中包含的uiimageview创建自己的uiimageview。
下面的代码>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] init];
ItemForSale *item = [listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = item.name;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont systemFontOfSize:14];
NSURL *url = [NSURL URLWithString: item.imgPath];
UIImage *thumbnail = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
if (thumbnail == nil) {
thumbnail = [UIImage imageNamed:@"noimage.png"] ;
}
cell.imageView.image = thumbnail;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.frame = CGRectMake(0, 0, 40, 40);
cell.imageView.autoresizingMask = UIViewAutoresizingNone;
cell.imageView.clipsToBounds = YES;
return cell;
}
我试图设定内容模式(尝试都aspectfill和方面配合),试图复位帧,设定autoresizingmask,clipTobound。没有一件事改变了一件事。
我只是试图用一个自定义的uiimageview,它工作正常。必须是在uitableviewcell中包含的uimageview的东西 – Augie 2012-08-07 13:58:41