SWIFT:navigationviewcontroller不会将应用程序过渡到另一个视图控制器

时间:2020-08-12 13:18:10

标签: ios swift xcode macos tvos

   @IBAction func activateDidTouch(_ sender: AnyObject) {
    
    /*Testing transitioning to another view controller just by a button click**/
    print("Activate Did Touch was triggered")
    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc: LoginViewController = storyboard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
            self.navigationController?.pushViewController(vc, animated: true)

}}

当我单击与该功能连接的按钮时,什么也没发生。
确实会打印出来:

print("Activate Did Touch was triggered")

我已经验证了ViewController标识符。因此,从理论上讲,所有事情都应该起作用。

enter image description here

1 个答案:

答案 0 :(得分:-1)

我尝试了提到的第二种方法here,它解决了我的问题:

let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
//self.navigationController?.pushViewController(vc, animated: true)
self.present(vc, animated: true, completion: nil)