ios - UINavigationController 推送崩溃

标签 ios uiviewcontroller uinavigationcontroller pushviewcontroller

我有一个 NestedViewController,我正在尝试将其插入 UINavigationController 中。这会导致崩溃并显示以下堆栈跟踪:

enter image description here

另外:

  • 所有这些都发生在主线程上
  • 这会在 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 。

enter image description here

场景树开始看起来像这样:

enter image description here

然后,当然,我删除了 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/

相关文章:

ios - 将 UIViewController 更改为 UITableViewController

ios - VC 之间的 Swift Segue,无需链接

ios - 如何确定 View 是从 navigationController 中的 "More"还是从主选项卡加载的?

iOS:如何在 GLES2 中渲染到 1 channel 纹理

iphone - 找出 iPhone 有多少内存?

iphone - 如何在 UITabBar (iOS) 中禁用栏项目的标题

ios - 如何更改详细 View Controller 中的后退按钮颜色?

ios - 从 xcode ios 中删除未使用的方法

ios - 在 Swift 中将图像发送到 ViewController 的多个实例

ios - 我如何从 UINavigationController 转到 UIViewController