I have a modal VC and I have dragged in a navigation bar using storyboard:
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
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"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.