【发布时间】:2020-05-21 11:51:42
【问题描述】:
我需要在 UITableView 中显示以下结构。我在 MainTableViewCell 中创建了 childTableView。另外两个 tableviewCell 都需要根据描述计算动态高度。
[
{
"schedule_type": "appointment",
"schedule_id": “1234”,
“schedule_desc”: “This is long text. Needs to mange with dynamic height in UILabel”,
“activities” : [
{
“activity_id” : “12”,
“activity_desc” : “long description”
},
{
“activity_id” : “123”,
“activity_desc” : “long description”
},
{
“activity_id” : “121”,
“activity_desc” : “long description”
}
]
},
{
"schedule_type": "appointment",
"schedule_id": “1234”,
“schedule_desc”: “This is long text. Needs to mange with dynamic height in UILabel”,
“activities” : [
{
“activity_id” : “12”,
“activity_desc” : “long description”
},
{
“activity_id” : “123”,
“activity_desc” : “long description”
},
{
“activity_id” : “121”,
“activity_desc” : “long description”
}
]
}
]
为了计算动态高度,我在 MainTableViewCell 中编写了以下代码。
self.childTable.dataSource = self;
self.childTable.delegate = self;
[self.childTable reloadData];
[self.childTable layoutIfNeeded];
self.childViewHeightConstraint.constant = self.childTable.contentSize.height
但是当我设置断点来计算 childTableView 高度时,它给了我单元格的默认值,即 44。因此,它没有根据内容进行更新,我的整个单元格看起来很乱。
我的方法是正确的还是有其他更好的方法可以在 tableview 中实现上述数据?
【问题讨论】:
标签: ios objective-c uitableview