表视图单元从View Controller返回到Table View Controller时“跳转”

我有一个TableViewController ,并单击一个自定义单元格将您带到相关的WebViewController

我遇到的问题是,当我点击WebViewController的“返回” TableViewController的表视图单元格“跳转”。

在这里输入图像说明

一旦桌面视图开始滚动,他们都跳回到正确的高度。 所以我假设它与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.我正在使用自动布局和故事板。

Custom Cell 2的其他Storyboard信息: 在这里输入图像说明在这里输入图像说明

故事板约束:

在这里输入图像说明

我相信你没有正确设置约束。 我有一个类似于以前的问题,并通过在UILabel上设置Leading,Trailing,Top和Bottom间距的约束来解决。

玩弄约束。 行为将开始改变。 继续下去,直到你得到你想要的。

这似乎不是来自专业人士的技术性答案。 但是,这是如何得到解决与那些苹果没有正确引入的虚拟约束。

另外,请尝试[cell setNeedsUpdateConstraints]; 在cellForRowAtIndexPath中返回单元格之前。 和: [cell setNeedsLayout];

我终于解决了这个问题,关键是要计算一个估计的高度。 看起来像你回报的估计越准确,跳跃/颠簸越less。

 - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { switch (yourTypeOfCell) { case something: return estimatedHeight; break; case default: return defaultValue; break; } } 

尝试在viewDidLoad中为你的UITableView设置estimatedRowHeight来帮助UIKit猜测你的tableView的行高

 - (void)viewDidLoad { [super viewDidLoad]; self.tableView.estimatedRowHeight = 490.0; }