【发布时间】: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