简体   繁体   中英

Swift Changing Navigation Bar in a ViewController

So here's my problem. I added a empty ViewController to a NavigationController. The problem is that when I add a View to the empty ViewController the navigation bar becomes unclickable I can't add back buttons or change the title.

I'm using Xcode 6.1 6A1052d.

You don't add buttons directly to navigation, but to the navigationItem of contained view controller. For example,

class ContainedViewController : UIViewController {
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: nil, action: 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