user3766930 user3766930 - 1 month ago 4x
Swift Question

Why I cannot set a title of my UINavigationController in Swift?

I have a

in my app and I added there the segmented control:

enter image description here

I also have a button and when user presses it, I want to hide the navigation control and display a string instead.

I can hide the segmented control by doing:

segmentedControl.hidden = true

and it works, but when I write in the code:

self.title = "test"

then the test word does not appear. What's the problem here and how can I fix it?


If you have already set titleView of navigationItem and trying to set title then you need to first set titleView as nil then only it will display your title on NavigationBar.

self.navigationItem.titleView = nil
self.navigationItem.title = "Test"