I had a similar problem. When the user leaves my app to change the color scheme in ‘Settings’, the navigation bar, text, and color attributes needed to be updated. I was able to update the nav bar color but the nav bar text color was not getting updated. My solution: I am not using ‘Storyboards’. In my AppDelegate.h
I have:
@property (….) CustomViewController *viewController;
@property (….) UINavigationController *nav;
I did not @synthesize
in AppDelegate.m
. Then in AppDidFinishLaunchingWithOptions:
….
self.viewController = [[CustomViewController alloc ….initWithNib….
[self setNavControllerAttributes]; // My solution is in this method
self.window.rootViewController = self.nav;
….
The method that does most of the work is in AppDelegate.m
- (void) setNavControllerAttributes
{
self.nav = nil;
self.nav = [[UINavigationController alloc…
// Set my attributes with dictionary options and such
self.window.rootViewController = self.nav;
}
I know I am setting the *nav
to nil
even the first time the app runs but it works and it will be also set to nil
when the user leaves and relaunches the app. My only concern would be the fact that I am reassigning the rootViewController
to window
, but I think ARC will take care of my memory management.
To make this work I call the method again on re-launch in my applicationWillEnterForeground:
[self setNavControllerAttributes];
I’m sure you can tweak it to your needs. The only other thing to watch out for, I guess, is saving your data because when you set *nav
to nil
, you may deallocate the child controllers and lose data. This works for iOS 6. If I notice that a different approach is needed for iOS 7, I will come back and update. If anyone has additional suggestions I will take the advice. I hope this helps
In applicationWillEnterForeground:
you can even do something better to minimize memory and performance overhead. Currently this is my method to also update the first view controller
if (self.viewController.isViewLoaded) {
[self setNavControllerAttributes];
[self.viewController viewWillAppear:YES];
}
if (self.viewController.view.window) {
// Perform other action if code above doesn't work
}