Set the dynamic table of the honeycomb table. The height of the contents of the table to the height of the table. Ios

I have a tableview (A) each user cell having a tableview (B) with a table dynamic view cell.

In 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];
}

In tableview (A), the user reloads the table table (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 are the table view height limits (B) in a child of tableview (A). tableBHeightConstraints.constant does not get the correct value with all calculations.

Which place is better or better to get tableView.contentSize.height exactly after setting the dynamic height of the table cell.

This is a tableview element (A) enter image description here

enter image description here

This is the table (B) Cell

Please help the guys.

+4
5

viewDidLoad.

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

measuredHeightForRowAtIndexPath :

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

heightForRowAtIndexPath. , .

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

, , , . , - .

+4

:

UItableView

_tableViewHieghtConstraint.constant = * .

.

+1

, - . , tableView tableCell, , . , , , .

, tableView .

+1

:

tableA_cell.contentView height = TableB height

:

NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(tableB);
[cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V|[tableB|" options:0 metrics:0 views:viewsDictionary];

.

- tableB,

[self.tableView beginUpdates]
[self.tableView endUpdates]

in table A to automatically update the height of its cells

0
source

Try moving the changes from -(void) updateConstraintsto -(void) viewDidLayoutSubviews.

-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];

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

}

0
source

All Articles