gpt4 book ai didi

ios - 设置Dynamic Cell的Table View Content height为table view height constraints ios

转载 作者:可可西里 更新时间:2023-11-01 05:19:44 25 4
gpt4 key购买 nike

我有 tableview(A) 的每个自定义单元格都有 tableview(B) 和动态表格 View 单元格。

在 tableview(A) cellForRowAtIndex。

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

MainMessageTVCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MsgMainCell"];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

NSInteger index = indexPath.row;

MessageMain *result = tableData[index];

cell.dateLabelTC.text = [NSString stringWithFormat:@"Date : %@",result.createdTime];
cell.subjectLabelTC.text = [NSString stringWithFormat:@"Subject : %@",result.subject];

NSArray *arrList = result.messageList;
[cell setupTableData:(NSMutableArray *)arrList];

[cell setNeedsUpdateConstraints];
}

在 tableview(A) 的自定义单元格重新加载 tableview(B)。

-(void)setupTableData:(NSMutableArray *)tableData{

_tableData = tableData;

[self.tableView reloadData];
}
-(void)updateConstraints{
[super updateConstraints];

dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView layoutIfNeeded];
CGFloat height = self.tableView.contentSize.height;//+1000;
tableBHeightConstraints.constant = height;
});
}

tableBHeightConstraints 是 TableView (B)在 TableView (A)的子单元格中的高度约束。tableBHeightConstraints.constant 没有得到所有计算约束的正确值。

在动态表格单元格的高度设置之后,什么是获得 tableView.contentSize.height 的最佳位置或方法。

这是 tableview(A) 的 Cell enter image description here

enter image description here

这是 tableview(B) 的单元格

请大家帮忙

最佳答案

在您的 viewDidLoad 方法中添加以下代码。

   self.tableView.rowHeight = UITableViewAutomaticDimension;
[self.tableView setEstimatedRowHeight:85.0];

还包括 estimatedHeightForRowAtIndexPath 方法并返回估计的行高,如下所示,

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

为 heightForRowAtIndexPath 分配一个自动维度。该方法要求委托(delegate)提供用于指定位置的行的高度。

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

注意

要使表格行具有动态高度,contentview 中的标签必须固定到顶部和底部,以便它们可以根据内容缩小或增大。如果您遇到任何困难,请及时通知我。

关于ios - 设置Dynamic Cell的Table View Content height为table view height constraints ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37895050/

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