Swift Navigation Bar Button and Title don't appear

Joe picture Joe · Aug 20, 2014 · Viewed 36k times · Source

I'd like to create a Navigation bar on top of my App. I created an Navigation Controller -> Tab Bar Controller -> Navigation Controller -> Table Controller

  1. I dragged a Bar Button Item on the upper right side.
  2. I double clicked the title in the middle of the Table Controller and wrote a text.
  3. I also tried it with this code in the viewDidLoad() of my controller:

    self.navigationController.navigationBar.topItem.title = "some title"
    self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Search, target: self, action: "barButtonItemClicked:"), animated: true)
    self.navigationItem.title = "YourTitle"
    

Non of it worked - what am I doing wrong? :/

Answer

Va Visal picture Va Visal · Oct 24, 2014

You can try something like this:

self.title = "Your Title"

var homeButton : UIBarButtonItem = UIBarButtonItem(title: "LeftButtonTitle", style: UIBarButtonItemStyle.Plain, target: self, action: "")

var logButton : UIBarButtonItem = UIBarButtonItem(title: "RigthButtonTitle", style: UIBarButtonItemStyle.Plain, target: self, action: "")

self.navigationItem.leftBarButtonItem = homeButton
self.navigationItem.rightBarButtonItem = logButton