簡體   English   中英

具有特定大小的表視圖單元格圖像

[英]Table View cell image with specific size

我有一個TableView從Url加載圖像,一切都很好。 問題是當我向下或向上滾動時,單元格中的圖像變大。 有時它變得比細胞自身更大。

我已經嘗試了所有方法,但是沒有用,我將View模式設置為適合Aspect,但是仍然存在相同的問題。

她是我的代碼:

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

有人可以給我一個想法嗎?

也許您可以調整圖像框架的大小:

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

如果您緩存圖像,則應在使用圖像時設置其框架,而不僅是在完成下載時

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM