popViewControllerAnimated changes UINavigationBar's UIColor

499 Views Asked by At

I have a 'Back' UIBarButtonItem as you can see in the 4th ViewController

The Back button is connected to an IBAction:

- (IBAction)backClicked:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

But when I call popViewControllerAnimated: from the fourth ViewController to go back to the 3rd ViewController, it changes the original color of the Tab Bar Tab's UINavigationBar tintColor. The original navbar tintColor of the UITabBarController is set to green by the AppDelegate and the pop changes it to dark grey(the color of the 4th VC's navbar)

How do I not lose my navbar tintcolor when calling popViewControllerAnimated:?? Please help, I've been trying to figure this out for days.

2

There are 2 best solutions below

2
On

Check that you're not setting it in the viewWillAppear of the previous view.

0
On

Replace

[self.navigationController popViewControllerAnimated:YES];

with the following (this is the swift code)

self.dismissViewControllerAnimated(true, completion: nil)

You didn't use a navigation controller when you were adding the fourth view controller. That's why simply call dismissViewControllerAnimated method.

You have to use UINavigationController and its pop methods only when you add your view controllers via pushViewController method.

I learned this via - Go back to previous view controller doesn't work