Reputation: 2708
The titles in the DetailViewController
and RootController1
do not show. Also when back button is pressed in DetailViewController
, it pops to RearTV
instead of popping to RootController1
. Can anyone tell me how to customize the titles of the navigation bar shown on UIViewControllers?
Initial ViewController is of type SWRevealViewController
Custom segue from SWRevealViewController to NavigationController
From the Navigation Controller to RearTV (a UITableViewController with static cells holding several buttons) there is a relationship of "root view controller to RearTV"
From a button on RearTV to VC2 (a UIViewController having an embed container view placed on top of it) there is "Show" segue to VC2
From the container View in a VC2 there is an Embed Segue to "Split View Controller"
5.1 From the split view controller to Navigation Controller (the one to the right) there is a relationship of "master view controller to Navigation Controller"
5.1.2 From the Navigation Controller (the one to the right) to the root controller there is a relationship of "root view controller to Root Controller1"
5.1.3 From the root controller (named "Root Controller1") to Navigation Controller ("the one underneath) there is a segue "showDetail1 to Navigation Controller"
5.2 From the split view controller to navigation controller ("the one underneath) there is a relationship "detail view controller to Navigation Controller"
Both in RootController1 and DetailViewController I am trying to show a title, but it shows nothing.
//centers the title of the navigation bar in all view controllers
struct CustomNavBar {
static func center(title: String) -> UILabel {
let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
titleLabel.text = title
titleLabel.adjustsFontSizeToFitWidth = true
titleLabel.textAlignment = NSTextAlignment.center
return titleLabel
}
}
override func viewDidLoad() {
super.viewDidLoad()
//attempt 1 to customize title of navigation bar
self.navigationController?.navigationItem.titleView = CustomNavBar.center(title: "some title")
//attempt 2 to customize title of navigation bar
self.navigationItem.titleView = CustomNavBar.center(title: "some title")
}
Upvotes: 0
Views: 3246
Reputation: 761
Try entering the following into your view controllers:
self.navigationController?.navigationBar.topItem?.titleView = CustomNavBar.left(title: "some title")
as opposed to:
self.navigationController?.navigationItem.titleView = CustomNavBar.center(title: "some title")
This only works when I include the Structure in the controllers.
Upvotes: 1