简体   繁体   中英

How to add Navigation bar programmatically by clicking the button

I have Login, Signup and Reset viewControllers I have connected the UINavigation controller to login controller but when I go to other view controllers by clicking the button like signup or reset password the destination controller appears without navigation bar. help to include navigation bar programmatically when I click the below button.

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

For display navigation bar you need to add your SignUpViewController in UINavigationController you can add directly in storyboard By

Selecting SignUpViewController -> Editor Menu -> Embed in -> Navigation Controller

OR

you can add programmatically like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM