为什么模态presenting视图控制器break自动布局在我的表视图? [英] Why does modally presenting a view controller break Auto Layout in my table view?

查看:156
本文介绍了为什么模态presenting视图控制器break自动布局在我的表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例项目: http://cl.ly/1o2K2m2r262q

我有一个的UITableView 与具有自动布局自己的身高自动计算定制单元。定制的细胞具有在其内三个标签,每个定位成彼此和内容视图之间的垂直间距,并从左侧推开

I have a UITableView with custom cells that have their height auto-calculated from Auto Layout. The custom cells has three labels within it, each positioned with vertical spacing between one another and the content view, and pushed away from the left side.

它的伟大工程,当我输入数据,并将其装入。

It works great when I input the data and it loads.

然而,当我有模式present从托管表视图视图控制器视图控制器,我发现它完全打破了自动布局,因为我返回到原来的视图控制器。

However when I modally present a view controller from the view controller hosting the table view, I notice it completely breaks Auto Layout as I return to the original view controller.

什么原因呢?我填充数据到一个简单数组作为其型号为表视图的数据源,那么它只是自动布局。它是这样一个简单的项目,我很困惑的地方它会被搞乱了。

What would cause this? I populate the data into a simple array that acts as the model for the table view's data source, then it's just Auto Layout. It's such a simple project that I'm confused where it would be messing up.

增加:我AP preciate rdelmar的答案,但我根本无法相信,有没有一个的单一的应用程序的出货,现在是采取这种动态的优势未做可怕的跳跃表视图的iOS 8的细胞功能。这将是令人难以置信的明显。一定有人想出一个办法,使这项工作,否则他们绝不会运了。

Addition: I appreciate rdelmar's answer, but I simply can't believe that there's not a single app shipped right now that takes advantage of this dynamic cell feature of iOS 8 without making terribly jumpy table views. It would be incredibly noticeable. Someone must have figured out a way to make this work, otherwise they never would have shipped it.

推荐答案

您有几个问题。在故事板,还有在场景列表中的红色警示箭头。你不应该忽视。点击它,让它暗示变化(先做好COM pression电阻值,我觉得内容拥抱人去自行消失)。

You have several problems. In the storyboard, there is a red warning arrow in the scene list. You shouldn't ignore that. Click on it and make the changes it suggests (do the compression resistance values first, and I think the content hugging one goes away on its own).

在MasterViewController的viewDidLoad,添加你需要自我调整大小细胞这两行,

In MasterViewController's viewDidLoad, add these two lines that you need for self-sizing cells,

self.tableView.estimatedRowHeight = 120
self.tableView.rowHeight = UITableViewAutomaticDimension // you may not need this one, I think it might be the default now

最后,我发现,当我提出在故事板的单元格(如code反对),我需要将下面的方法添加到单元格级,所以布局情况马上(否则它直到您滚动或转动不正常布局),

Finally, I've found that when I make the cell in the storyboard (as opposed to in code), I need to add the following method to the cell class, so the layout happens right away (otherwise it doesn't layout properly until you scroll or rotate),

override func didMoveToSuperview() {
        self.layoutIfNeeded()
    }

这篇关于为什么模态presenting视图控制器break自动布局在我的表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆