简体   繁体   中英

Custom navigation bar for pushed UIViewController

How do I set a title and buttons on the navigation bar of a pushed view controller if I push it onto navigationController with navigationController.pushViewController(controller:animated:completion:) , whilst keeping the " Back " button?

Thank you in advance!

For anyone wondering how to do this, just override your pushed UIViewController 's navigationItem property directly. My mistake was that I was trying to accomplish this with self.navigationController?.navigationItem

Here is the code, that you should write in order to set the navigation title as well as left button

Code :

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    //For Setting Title
    self.title = "New Title";

    //For setting button in place of back button
    let leftItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "leftButtonClicked");
    self.navigationItem.leftBarButtonItem = leftItem;
}

Happy coding ...

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