3
votes

I combine tabbarcontroller with navigationcontroller. I set navigationitem title by using,

self.tabBarController?.navigationItem.title = "first"

for first page

self.tabBarController?.navigationItem.title = "second"

for second page,and the title showed.

But when I switch to second page, and switch back to first page, the title still display as second.It doesn't changed back to first.

How can i fix it?

2
Use viewWillAppear rather than viewDidload to update the title. may be it will help you. - Himanshu
@Himanshu thank you for reply, i just try and it works. Thank you. - evelyn

2 Answers

0
votes

Try to set title in your view Controller's viewDidLoad Method as following :

self.navigationItem.title = "First Page" // in First Page ViewController

self.navigationItem.title = "Second Page" // in Second Page View Controller

So that whenever you're switching to other viewcontrollers, the title will set accordingly..

Hope it helps..

0
votes

Try to set title in your view Controller's viewDidAppear Method

func viewDidAppear(animated: Bool)
{
    self.tabBarController?.navigationItem.title = "first" 
}

for first page

func viewDidAppear(animated: Bool)
{
    self.tabBarController?.navigationItem.title = "second" 
}

for second page