Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent UITabBarItem's title from being overwritten by the controller title?

Tags:

ios

swift

If I set the tab bar item title in the storyboard or from code (see below), it is changed to that tab's view controller title when I tap the tab and the controller loads. I don't want this.

I want the tab bar item title that I set in the storyboard or from code to remain, without being changed. How do I achieve that?

I still want to set the controller title for the UINavigationController to show on back buttons etc.

override func viewDidLoad() {
    super.viewDidLoad()

    tabBarItem.title = "Keep me"

    // But this overrides it, which I don't want.
    title = "Don't let me change the tab bar title"
}
like image 937
Henrik N Avatar asked Mar 07 '23 20:03

Henrik N


1 Answers

you can change

title = "Don't let me change the tab bar title"

to

navigationItem.title = "Don't let me change the tab bar title"

edit:

override var title: String? {
    didSet{
        tabBarItem.title = "you want"
    }
}
like image 52
NF Lee Avatar answered Apr 09 '23 02:04

NF Lee