2

enter image description here

I have to calculate dynamic height of cell depends on two label, left label and right label. left label can have empty string . I want to give a specific fixed height if left label is empty else it will take left label height. Cant able to give fixed height when label is empty This code is not working

self.tableView.estimatedRowHeight = 50

enter image description here

0

2 Answers 2

2

Your constraint for your both label should be,

top,bottom,leading and trailing.

and set below code in your viewDidload

 self.tableView.estimatedRowHeight = 50
 self.tableView.rowHeight = UITableViewAutomaticDimension;
Sign up to request clarification or add additional context in comments.

Comments

1

Set constraints from top and bottom of the cell to both labels. Then add the following code in your view controller

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.