【问题标题】:How to add Navigation bar programmatically by clicking the button如何通过单击按钮以编程方式添加导航栏
【发布时间】:2019-05-03 14:41:45
【问题描述】:

我有登录、注册和重置视图控制器 我已将 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)
}

【问题讨论】:

  • 查看我的答案

标签: ios swift uinavigationcontroller uinavigationbar


【解决方案1】:

对于显示导航栏,您需要在UINavigationController中添加您的SignUpViewController,您可以直接在情节提要中添加通过

选择 SignUpViewController -> 编辑器菜单 -> 嵌入 -> 导航控制器

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

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)
}

【讨论】:

  • 非常感谢亲爱的@jignesh Vadadoriya
  • 欢迎你来
猜你喜欢
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-25
  • 2012-06-21
  • 2013-05-02
相关资源
最近更新 更多