我的UITableViewCell的Autolayout在查看时按预期工作,但是当我选择一行时,UI将会中断,此单元格的高度也将恢复为默认值。
对于与细胞相关的代码,我只是按照本教程“Using Auto Layout in UITableView for dynamic cell layouts & variable row heights”
进行操作不幸的是,本教程不包括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];
}