导航不出现 Xcode 8.1 iOS 10 Swift 3
Posted
技术标签:
【中文标题】导航不出现 Xcode 8.1 iOS 10 Swift 3【英文标题】:Navigation does not appear 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)
【问题讨论】:
导航控制器有一个显示导航栏的选项。检查它是否被选中。 我已经更新了问题并且导航栏已启用 你可能会看到图片 哦,登录有导航栏。请告诉我您的主屏幕是哪个? 最后一行中间一个是家 【参考方案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)
【讨论】:
以上是关于导航不出现 Xcode 8.1 iOS 10 Swift 3的主要内容,如果未能解决你的问题,请参考以下文章
从 iOS 11 上的左侧菜单导航后 Xcode 9 导航栏问题不在 iOS 10.3 及更低版本上