ios - 从 View Controller 返回到 TableView Controller 时 TableView 单元格 "jump"

标签 ios objective-c uitableview ios8 autolayout

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

我遇到的问题是,当我在 WebViewController 中点击“返回”时,TableViewController 中的 TableView 单元格“跳转”。

enter image description here

一旦表格 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信息: enter image description here enter image description here

Storyboard约束:

enter image description here

最佳答案

我认为您没有正确设置约束。我之前遇到过类似的问题,通过为 UILabel 设置前导、尾随、顶部和底部间距的约束来解决。

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

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

此外,在返回 cellForRowAtIndexPath 中的单元格之前,请尝试 [cell setNeedsUpdateConstraints];。 并且:[cell setNeedsLayout];

关于ios - 从 View Controller 返回到 TableView Controller 时 TableView 单元格 "jump",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26948664/

相关文章:

objective-c - iOS - 对多个对象的单一委托(delegate)。如何改变行为?

ios - 点击单元格时,应添加注释

ios - UITableview 在 background-transfer-service-ios7/中没有更新

iOS swift : UITableView KeyPad overlay

ios - 如何从我们的 View 中删除 AVPlayerViewController?

ios - 如何在 Objective-C 中测试代理对象上的选择器?

ios - 关于 UIGestureRecognizer

javascript - 在 javascript 中调用原生的 swift 函数

objective-c - 将 mac osx 应用程序转换为 ios 应用程序的最简单方法

ios - didDeselectRowAtIndexPath 没有在 UITableView 的第一行被调用