选择时,UITableViewCell的Autolayout不起作用

时间:2015-03-19 09:52:26

标签: ios objective-c uitableview autolayout

我的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];
}

0 个答案:

没有答案