我有一个 TableViewController
,单击自定义单元格会将您带到相关的 WebViewController
。
我遇到的问题是,当我在 WebViewController
中点击“返回”时,TableViewController
中的 TableView 单元格“跳转”。
一旦表格 View 开始滚动,它们都会跳回到正确的高度。所以我假设它与 TableViewController
自定义单元格的高度有关,但我不完全确定。
TableViewController.m
尝试过:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[Two self]]) {
return 490; // As of 11/13/14
} else { // 2 other custom cells
return tableView.rowHeight; // return the default height
}
}
还试过:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[One self]]) {
ListTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:@"1Cell"];
CGFloat heightOne = [cellOne.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightOne + 2;
} else if ([model isKindOfClass:[Two self]]) {
ListTableViewCellTwo *cellTwo = [tableView dequeueReusableCellWithIdentifier:@"2Cell"];
CGFloat heightTwo = [cellTwo.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightTwo + 400;
} else if ([model isKindOfClass:[Three self]]) {
ListTableViewCellThree *cellThree = [tableView dequeueReusableCellWithIdentifier:@"3Cell"];
CGFloat heightThree = [cellThree.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightThree + 2;
} else {
return 300;
}
}
更新:
还尝试了 [cell setNeedsUpdateConstraints];
和 [cell setNeedsLayout];
。
还尝试设置 estimatedHeight
多个不同的点,并同时添加了 Automatic Row Dimension
。
帮助将不胜感激!将发布任何需要的额外信息。谢谢!
我只支持 iOS 8。我使用的是自动布局和 Storyboard。
Custom Cell 2 的其他 Storyboard信息:
Storyboard约束:
最佳答案
我认为您没有正确设置约束。我之前遇到过类似的问题,通过为 UILabel 设置前导、尾随、顶部和底部间距的约束来解决。
玩弄约束。行为将开始改变。继续前进,直到你得到你想要的。
这似乎不是专业人士的技术性回答。但是,它是如何通过苹果没有正确引入的那些虚拟约束来解决的。
此外,在返回 cellForRowAtIndexPath 中的单元格之前,请尝试 [cell setNeedsUpdateConstraints];
。
并且:[cell setNeedsLayout];
关于ios - 从 View Controller 返回到 TableView Controller 时 TableView 单元格 "jump",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26948664/