I have a UITableView inside a UITableViewCell pinned on all four sides. I want to change the height of UITableView based on number of cells it has. For that I have subclassed UITableViewCell (name- TableCell). Inside it, I am using this code to update the tableView height.:
-(void)layoutSubviews{
[super layoutSubviews];
if ([self.data count] <= 5) {
self.tableHeightConstraint.constant = ([self.data count]) * 44.0f;
} else {
self.tableHeightConstraint.constant = 5 * 44.0f;
}
}
I change the height constraint of TableView above dynamically. It works sometimes but other times leads to breaking constraints leading to jittery behaviour of app.
Is this the correct way of changing height? Please help!
Edit 1:
I am inserting and deleting cells at runtime. The inserted cell has a tableview whose size is dynamic based on number of cells. When I insert (while including the above code) the insertion is correct. But when I delete, the cell (having uitableview) is still visible. When I scroll the cell out of screen, then only it goes invisible. Kindly help!