views:

1798

answers:

3

Greetings! I have set my UINavigationBar's barStyle to UIBarStyleBlack, and the tintColor to a color (other than black so as to get the color/gradient going). That much works well.

Now ... let's say I push a new view controller onto the nav controller stack. In this particular VC, I want the nav bar to turn black, but only within this VC.

So, in the new VC's viewWillAppear: method, I set the nav bar's tintColor to nil (or [UIColor blackColor] - either one works). In viewWillDisappear:, I change the tintColor back to what it originally was. Again, all is well.

Until I go back into the new VC a second (or additional) time. If I do that, the nav bar turns black again, but NOT the left bar button item! Instead, it keeps the original color from the parent VC!

I've looked at all manner of sample code (even Joe Hewitt's Three20 library, which appears to do the same thing mine does for its Photo controller/browser). As far as I can tell, I'm doing all the right things, but I'm stumped as to why the bar button item isn't being changed to black for all but the first time I enter my new VC.

Clues welcome/appreciated!

A: 

From what I hear this is a known 3.0 bug.

Steve Weller
Really now! Do tell.
Joe D'Andrea
Looked on http://openradar.appspot.com/ but didn't find anything. :(
Joe D'Andrea
It appears to be fixed in 3.1.
Joe D'Andrea
A: 

Try add to PARENT view controller:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", @"") style:UIBarButtonItemStylePlain target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backButton];
    [backButton release];
}
Pavel Kurta
By parent, do you mean the parent of the view controller having the problem? Wouldn’t that put the back button one level too high?(Update: This appears fixed in 3.1!)
Joe D'Andrea
A: 
    for (UIView *view in self.navigationController.navigationBar.subviews)
    {
        [view setNeedsDisplay];
    }

Hope it helps.

DImich
Hmm. Not 100% sure I'm comfy with that. From the UINavigationBar docs: "Unlike other types of views, you do not add subviews to a navigation bar directly." Thus, if we don't add them, we don't actually "know" about them. I'm just not sure if our using setNeedsDisplay here - handy as it is - will always work the way we expect going forward (not quote-knowing-unquote what all the subviews are). "... you should let the navigation controller manage the stack of navigation items and not attempt to modify these items yourself." Meanwhile, this has been fixed by Apple in 3.1, so that's a good thing!
Joe D'Andrea