gpt4 book ai didi

ios - UITableview单元格高度根据图像问题

转载 作者:行者123 更新时间:2023-12-01 17:11:28 24 4
gpt4 key购买 nike

我正在按照UIImageView的高度在做UITableview单元格的高度(动态高度),目前工作正常,但是我的问题是UITableview不能平滑滚动,或者如果我快速滚动则无法正常工作

我认为问题是我正在重新加载tableview单元格中的行,因此tableview滚动不起作用,有人可以告诉我对此问题的任何好的建议吗?

这是我做的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

// Create the cell...

[cell.myImageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (image != nil) {
[self.images insertObject:image atIndex:indexPath.row];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES];
}
}];
return cell;
}

用于根据图像设置高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id image = [self.images objectAtIndex:indexPath.row];
if ([image isKindOfClass:[NSNull class]]) {
return defaultHeight;
} else {
return [image size].height + topPadding + bottomPadding;
}
}

最佳答案

尝试这个

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *image = [self.images objectAtIndex: indexPath.row];
if (image) {
return image.size.height + 5;
}
else {
return 80.0; //default value......
}
}

关于ios - UITableview单元格高度根据图像问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42413229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com