在viewDidLoad上super的错误引用

问题描述 投票:-2回答:1

我需要从第一个实例化第二个控制器。初始化从如图所示的按钮开始。

以编程方式添加了代码和视图。加载从一个按钮开始

在情节提要文件中,视图未连接

第一控制者,呼叫者

let vc = storyboard?.instantiateViewController(withIdentifier: "vcID") as? SecondController
self.navigationController?.pushViewController(vc!, animated: true)

第二个控制器,被叫

    override func viewDidLoad() {
        super.viewDidLoad()

        // Barra di navigazione
        self.navigationController?.isNavigationBarHidden = false
        self.navigationItem.largeTitleDisplayMode = .never
        self.navigationItem.title = "Title here"

        let attrs = [
            NSAttributedString.Key.foregroundColor: UIColor.blue,
            NSAttributedString.Key.font: UIFont(name: "Nunito-Bold", size: 24)!
        ]

        self.navigationController?.navigationBar.titleTextAttributes = attrs
        self.navigationController?.navigationBar.largeTitleTextAttributes = attrs


    }

代码崩溃,导致调用初始视图控制器,然后在导航中调用多个控制器。看起来控制器失去了对调用方的引用。关于如何验证控制器参考的任何想法?

在初始视图中显示的错误代码是

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

在第二个控制器中原始

ios swift xcode uiviewcontroller
1个回答
0
投票

不知道错误代码,请尝试以下操作

if let vc = storyboard?.instantiateViewController(withIdentifier: "vcID") as? SecondController {
  let nav = UINavigationController(rootViewController: vc)
  self.present(nav, animated: true, completion: nil)
}

您确定“ vcID”与情节提要板上的一样正确吗?>

© www.soinside.com 2019 - 2024. All rights reserved.