5

I have a modal VC and I have dragged in a navigation bar using storyboard:

enter image description here

But now I can only change the title in storyboard and not in code. I need to be able to change it in code since the title will be dynamic.

I have tried both of these:

self.title = "some title"

navigationBar.topItem.title = "some title"

But none of them work and I dont get any warning/error either

user2636197
  • 3,982
  • 9
  • 48
  • 69

1 Answers1

8

If your NavigationBar is connected to your ViewController per Outlet, this works fine:

class ViewController: UIViewController {

    @IBOutlet weak var navigationbar: UINavigationBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationbar.topItem!.title = "Dynamic"
    }

}
dersvenhesse
  • 6,276
  • 2
  • 32
  • 53