gpt4 book ai didi

iOS 如何在没有自动布局的情况下设置动态 tableview 单元格高度?

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:11 25 4
gpt4 key购买 nike

我正在使用带有三个标签标题、日期和描述的自定义 tableview 单元格,现在我从网络服务获取数据,其中一些描述文本太大而无法在描述标签的框架内调整

如何进行?

最佳答案

简单地使用喜欢

ObjectiVe-C

- (void)viewDidLoad
{
...
...
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}

swift

 override func viewDidLoad() {


self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension

}

ObjectiVe-C

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80; // customize the height
}

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

swift

 func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80 // customize the height
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

最后在属性中或以编程方式设置您的 label.numofLines = 0

关于iOS 如何在没有自动布局的情况下设置动态 tableview 单元格高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38475311/

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