Autolayout of my UITableViewCell works as expected when viewing, but when I selecting a row, the UI will break, and the height of this cell will also back to default value.
For cell-related code, I just followed this tutorial "Using Auto Layout in UITableView for dynamic cell layouts & variable row heights"
Unfortunately, this tutorial doesn't cover selection part of UITableViewCell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = ...
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController pushViewController:MyViewController animated:YES];
}