ios – 返回主视图控制器时“仍需要自动布局…”崩溃

我的应用程序启动了一个菜单,它是UIViewController的自定义子类,名为LVSMainViewController.它嵌入在UINavigationController中,该控件被设置为故事板中的初始VC. LVSMainViewController实现-viewDidLayoutSubviews.

点击按钮会将用户带到应用程序的不同部分(不同的VC).用户通过连接到推送segue的按钮返回主菜单.但是,当应用程序再次加载主菜单VC时,它会崩溃并显示以下消息:

2014-08-28 16:11:14.122 * Assertion failure in -[UIView layoutSublayersOfLayer:],/SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8803

2014-08-28 16:11:14.257 * Terminating app due to uncaught exception ‘NSInternalInconsistencyException’,reason: ‘Auto Layout still required after sending -viewDidLayoutSubviews to the view controller. LVSMainViewController’s implementation needs to send -layoutSubviews to the view to invoke auto layout.’

SO上的其他帖子在以编程方式设置自动布局约束时报告相同的错误(我没有这样做,虽然我在故事板中使用自动布局)和/或使用UITableView时(我在主菜单中没有使用) VC或它所代表的VC,虽然我在应用程序的其他地方使用它). (见herehere.)

其他拼图:

>我尝试添加[self.view layoutSubviews];在-viewDidLayoutSubviews结束时.当我这样做时它不会崩溃.但自从Apple’s documentation年以来,这似乎是不明智的

You should not call this method directly. If you want to force a
layout update,call the setNeedsLayout method instead to do so prior
to the next drawing update.

>如果我改为添加[self.view setNeedsLayout];在-viewDidLayoutSubviews结束时,应用程序崩溃首先加载主菜单VC,而不是当我离开它并返回时.

可能是什么造成的?

解决方法

崩溃被神奇地修复的原因很可能是因为你现在正在使用iOS 8.你试过在iOS7上运行这个代码吗?

您可以通过调用[self.view layoutSubviews]来接近答案.

请尝试调用[self.view layoutIfNeeded].

看这些帖子:

Autolayout and subviews

Auto Layout error

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...