Reputation: 95
Sorry for the confusing title. My Setup is just as simple as following:
`Navigation Controller -> View Controller1 -> Tab Bar Controller -> View Controller2
-> View Controller3`
There is a show-segue, triggered by a BarButtonItem in ViewController1, which points to the TabBarController. For View Controller 2&3 (connected to the Tab Bar Controller), i configured the title and added a BarButtonItem on the top right. That's all. When I run the App, the title an buttons of VC2&3 are not shown, even if I set the title in the .swift-Class directly:
(self.navigationItem.title = "title of ViewController2"
)
Instead the simulator shows me a header with only a '< back' button in VC2&3.
What I want is the '< back' button + my title and right BarButtonItem. Sorry for asking such a trivial question, but I just can't find a solution.
I'm using Swift 2.1, Xcode 7.1, OS X 10.11.1 Thank you!
Upvotes: 1
Views: 1263
Reputation: 95
So, i finally found the solution for my case. ViewController1 can send the title for the VC2&3 in the prepareForSegue-method like:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let vc = segue.destinationViewController.navigationItem.title = "new title"
}
Or the better solution: ViewController2 set up its own title.
class ViewController2: UIViewController {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.visibleViewController?.navigationItem.title = "new title"
}
}
Upvotes: 2