presentViewController 在 iOS 8 上因 EXC_BAD_ACCESS 而崩溃

Posted

技术标签:

【中文标题】presentViewController 在 iOS 8 上因 EXC_BAD_ACCESS 而崩溃【英文标题】:presentViewController crashes with EXC_BAD_ACCESS on iOS 8 【发布时间】:2015-06-18 08:45:41 【问题描述】:

虽然在 ios 7 中一切都像一个魅力,但 presentViewController: 函数在 iOS 8 中使用超过一次时会崩溃。

var navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
presentViewController(navigationController, animated: true, completion: nil)

以上代码执行一次,没有任何问题,navigationController完美显示。关闭此 navigationController 并再次执行上述代码会使应用程序崩溃并出现 EXC_BAD_ACCESS 错误。

用于解除navigationController的代码如下:

self.dismissViewControllerAnimated(true, completion: nil)

注意 1:storyboardnavigationController 属性总是有正确的实例。我已经通过虚拟控制台确定了自己。

注意 2:并不总是在第二次,而是在第三次或第四次迭代。

谁能告诉我为什么会这样?

【问题讨论】:

【参考方案1】:

启用僵尸,并启用异常断点以查看崩溃的确切行。

【讨论】:

崩溃的确切行是:presentViewController(navigationController, animated: true, completion: nil)【参考方案2】:

经过一段时间在不同设备上的测试,我意识到这是 iOS 8.0.0 的一个错误。在iOS8.0.1-8.0.3之间解决的Bug。

我的办公室有不同的 iOS 版本的设备,问题只出现在 8.0.0 设备中。

【讨论】:

以上是关于presentViewController 在 iOS 8 上因 EXC_BAD_ACCESS 而崩溃的主要内容,如果未能解决你的问题,请参考以下文章

如何在封面视图和主页中使用“presentViewController”

PresentViewController 在 iOS 中隐藏导航栏

SKScene 在 presentViewController 之后重复

PresentViewController:动画不显示在 iPad 上

在 Swift 中的 presentViewController 之后调用 pushViewController

presentViewController:动画:完成:失败