如何通过单击按钮以编程方式添加导航栏

时间:2017-04-01 10:39:16

标签: ios swift uinavigationcontroller uinavigationbar

我有登录,注册和重置viewControllers我已将UINavigation控制器连接到登录控制器但是当我通过单击signupreset password按钮转到其他视图控制器时,目标控制器出现时没有导航酒吧。当我点击下面的按钮时,有助于以编程方式包含导航栏。

@IBAction func signupButton(_ sender: Any) {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "SignUpViewController") as! SignUpViewController
self.present(newViewController, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:1)

对于显示屏导航栏,您需要在SignUpViewController中添加UINavigationController,直接在故事板中添加<{p}}

选择SignUpViewController - &gt;编辑菜单 - &gt;嵌入 - &gt;导航控制器

您可以像这样以编程方式添加

IBAction func signupButton(_ sender: Any) {
     let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
     let newViewController = storyBoard.instantiateViewController(withIdentifier: "SignUpViewController") as! SignUpViewController
     let naviCon = UINavigationController(rootViewController:newViewController)
     self.present(naviCon, animated: true, completion: nil)
}