【问题标题】:SWIFT: navigationviewcontroller does not transition the app to another view controllerSWIFT:navigationviewcontroller 不会将应用程序转换到另一个视图控制器
【发布时间】:2020-08-12 13:18:10
【问题描述】:
   @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 标识符。所以理论上一切都应该有效。

【问题讨论】:

  • 当你使用.navigationController?. 之类的东西时,你是在说“如果我有导航控制器,请使用它;否则请继续,甚至不要告诉我有问题”。实际测试您的设置是否符合您的要求并打印一条消息,如果不是,则无需花费太多精力。
  • 我最近才开始学习 Swift。所以这对我来说不是那么明显。

标签: ios swift xcode macos tvos


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多