简体   繁体   English

具有特定大小的表视图单元格图像

[英]Table View cell image with specific size

I have a TableView that load images from my Url, everything's fine. 我有一个TableView从Url加载图像,一切都很好。 The problem is when I scroll down or up, the images become bigger in the cells. 问题是当我向下或向上滚动时,单元格中的图像变大。 Sometime it become bigger than the cell it's self. 有时它变得比细胞自身更大。

I have tried every thing, but it is not working, I am sitting the View mode to Aspect fit, but still have the same problem. 我已经尝试了所有方法,但是没有用,我将View模式设置为适合Aspect,但是仍然存在相同的问题。

Her is my code: 她是我的代码:

static NSString *cellIdentifier = @"Cell";
CellView *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

if (!cell) {
cell = [[CellView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}

ListOfObjects *listObjects;

cell.accessoryType = UITableViewCellAccessoryNone;
listObjects = [listArray objectAtIndex:indexPath.row];
cell.userName.text = userName;


ListOfObjects *venue = ((ListOfObjects * )self.listArray[indexPath.row]);
NSString *one = listObjects.theUserId;
NSURL *myUrl = [NSURL URLWithString:one];

if (listObjects.image) {
cell.imageView.image = listObjects.image;
} else {
// set default user image while image is being downloaded
cell.imageView.image = [UIImage imageNamed:@"second58.png"];

// download the image asynchronously
[self downloadImageWithURL:myUrl completionBlock:^(BOOL succeeded, UIImage *image) {
if (succeeded) {
// change the image in the cell

cell.imageView.image = image;

// cache the image for use later (when scrolling up)
venue.image = image;
}
}];
}

Can any one give me an idea about it? 有人可以给我一个想法吗?

Maybe you can resize image frame: 也许您可以调整图像框架的大小:

[self downloadImageWithURL:myUrl completionBlock:^(BOOL succeeded, UIImage *image) {
if (succeeded) {
cell.imageView.image = image;
cell.imageView.frame = your.frame;
}
}];

if you cache the image, you should set it's frame when you use it, not only when it finished download 如果您缓存图像,则应在使用图像时设置其框架,而不仅是在完成下载时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM