gpt4 book ai didi

ios - 具有动态高度的标准 UITableViewCell

转载 作者:技术小花猫 更新时间:2023-10-29 10:40:17 25 4
gpt4 key购买 nike

我想知道是否可以有一个标准 UITableViewCell有风格UITableViewCellStyleSubtitle有动态高度?

如果是,那么如何实现?

  • 我不想为单元格自定义和制作新的类和 Nib 。
  • 我已经设置了numberOfLines cell.textLabel的属性(property)和 cell.detailTextLabel0 .

好吧,如果你的 textLabel包含多行内容和detailTextLabel包含单行内容,tableView 会自动调整单元格高度。但如果它是相反的,那么它就不会!这是Apple的错误吗?或预期的功能?

下面是截图

enter image description here enter image description here

最佳答案

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

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

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

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text";
cell.detailTextLabel.numberOfLines = 0;
return cell;
}

关于ios - 具有动态高度的标准 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29791169/

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