1
votes

I'm using UITableViewAutomaticDimension for adjusting the cell height which has a dynamic label and an image.

tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = 80.0;

I want to resize the cell as the content of the label increases and it is working perfectly.

I want to keep a minimum height for the cell(say 80) for the image to fit in always even if the label has no content at all. I've applied autolayout and set constant height, width, top space and leading space constraints to the imageview. But the cell height is going lower than the constraint height when the label content is less.

What should I do to make the cells to keep a minimum height to fit the imageView while using the 'UITableViewAutomaticDimension' feature.

Thanks in advance.

4
Please check constrains of your layout for UITableViewAutomaticDimension work it need top constraints and bottom also if cell contains both constrains of any of cell subview it will work perfectly. - Hardik Thakkar

4 Answers

2
votes

Try to create an assistant hidden view, which set its top、bottom constraint to the contentView of cell, any width and x position, and then set its height Greater Than or Equal to 80.

0
votes

add ratio contraint

[self.tableview setNeedsLayout];

[self.tableview layoutIfNeeded];

[self.tableview reloadData];
0
votes

add ratio contraint and put the code where you want reload tableview

- (void)refreshWithData:(NSArray *)synopsissarr atIndex:(NSInteger)index {

    synopsisArray=synopsissarr;

    [self.tableview setNeedsLayout];

    [self.tableview layoutIfNeeded];

    [self.tableview reloadData];
-1
votes

highsun16 is right. I would have liked a bit more detail. Here's a demo project that provides all the detail necessary to replicate highsun16's answer:

enter image description here