【问题标题】:Navigation does not appear Xcode 8.1 iOS 10 Swift 3导航不出现 Xcode 8.1 iOS 10 Swift 3
【发布时间】:2017-01-10 11:03:35
【问题描述】:

当登录按钮移动到主页视图控制器时,导航栏不会出现,我已经设置了我的故事板并把所有东西都做好了,但我认为我在代码中被困在这一点上。

实际上没有segue,而是编码,所以我如何进行导航工作?

我用来执行导航的代码

 let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
 self.present(vc!, animated: true, completion: nil)

@IBAction func loginAction(_ sender: Any) {

    if self.emailTextField.text == "" || self.passwordTextField.text == "" {

        //Alert to tell the user that there was an error because they didn't fill anything in the textfields because they didn't fill anything in

        let alertController = UIAlertController(title: "Error", message: "Please enter an email and password.", preferredStyle: .alert)

        let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
        alertController.addAction(defaultAction)

        self.present(alertController, animated: true, completion: nil)

    } else {

        FIRAuth.auth()?.signIn(withEmail: self.emailTextField.text!, password: self.passwordTextField.text!) { (user, error) in

            if error == nil {

                //Print into the console if successfully logged in
                print("You have successfully logged in")

                //Go to the HomeViewController if the login is sucessful


                let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
                self.present(vc!, animated: true, completion: nil)

            } else {

                //Tells the user that there is an error and then gets firebase to tell them the error
                let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)

                let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
                alertController.addAction(defaultAction)

                self.present(alertController, animated: true, completion: nil)
            }
        }
    }
}

【问题讨论】:

  • 导航控制器有一个显示导航栏的选项。检查它是否被选中。
  • 我已经更新了问题并且导航栏已启用
  • 你可能会看到图片
  • 哦,登录有导航栏。请告诉我您的主屏幕是哪个?
  • 最后一行中间一个是家

标签: ios xcode uinavigationcontroller swift3 uinavigationbar


【解决方案1】:

替换你的代码:

 let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
 self.present(vc!, animated: true, completion: nil)

使用此代码:

 let vc : YourViewController = self.storyboard?.instantiateViewController(withIdentifier: "Home")as! YorViewController
 let navController = UINavigationController(rootViewController: vc)
 self.present(navController, animated: true, completion: nil)

您只是试图在没有导航的情况下呈现视图控制器。以编程方式给它导航,然后它将显示导航栏。

【讨论】:

  • 谢谢你souchhhhhhhhhh
  • 我没有 15 名声望,所以我不能投票 :( 但是一旦我的声望超过 15 名,我就会再次投票 :)
  • 亲爱的投票!_
【解决方案2】:

你真的在使用navigationController吗?如果是这样,应该是pushViewController 而不是present

navigationController?.pushViewController(vc, animated: true)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多