我有一个 NestedViewController,我正在尝试将其插入 UINavigationController 中。这会导致崩溃并显示以下堆栈跟踪:
另外:
- 所有这些都发生在主线程上
- 这会在 iOS 11 和 12 上重现
动画
标志不会改变任何内容- NestedViewController 以模态方式呈现在应用程序的其他位置,并且成功完成,没有崩溃
- NestedViewController 从 Storyboard获取其布局
- NestedViewController 的 View 以编程方式初始化且与 Storyboard布局相同,仍然会导致崩溃
- 推送空的 UIViewController 不会导致崩溃
我做错了什么?
UPD1:我做了这个,但这不会导致崩溃:
let controlla = { () -> UIViewController in
let cont = UIViewController()
cont.view = {
let view = UIView()
view.backgroundColor = UIColor.green
let stack = UIStackView(arrangedSubviews: [ {
let view = UIView()
view.backgroundColor = UIColor.yellow
view.snp.makeConstraints { make in
make.height.equalTo(128)
}
return view
}() ])
view.addSubview(stack)
stack.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview()
}
return view
}()
return cont
}()
controller.pushViewController(controlla, animated: true)
UPD2:根据用户 Adeel 的请求,评论中显示了中止断点命中后控制台中的内容:
libc++abi.dylib: terminating with uncaught exception of type NSException
如果事情如此简单并且消息就在那里,那么这个问题就不会真正存在,不是吗?
UPD3:为了扩展我的调查,我卸载了 View Controller 中除 Root View 之外的所有 View 。
场景树开始看起来像这样:
然后,当然,我删除了 View Controller 中的所有 socket 和代码。
它仍然崩溃。不过,模态现在仍然可以正常工作。
UPD4:为了以防万一,我将 NestedViewController 重命名为其他名称。没有成功。
UPD5:在 UPD1 之前,它看起来像这样:
controller.pushViewController(controller, animated: true)
最佳答案
如 UPD5 中所述,您插入导航 Controller 的 Controller 实际上就是同一个 Controller 本身。
关于ios - UINavigationController 推送崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57390607/