views:

62

answers:

1

In my tabBar based app I have subclassed the UINavigationBar. Let's say I have three of them: BlueNavBar, BlackNavBar and RedNavBar. It looks something like this:

        //BlueNavBar.m
        - (void)drawRect:(CGRect)rect {
            self.tintColor = [UIColor colorWithRed:65.0f/255.0f green:(156.0f/255.0f) blue:(215.0f/255.0f) alpha:1.0];
            UIImage *image = [[UIImage imageNamed:@"blueNavBar.png"]retain];    
            [image drawInRect:rect];
            [image release];    
        }

I've assigned the subclassed navigationbar for each tab with Interface Builder. That is working great, no problems there.

In some viewControllers however i want to change the navigationBar during "pushViewController". Let's say I want to change the current navigationbar (which is for e.g. BlueNavBar) to the RedNavBar. How can I do this programmatically, without Interface Builder?

A: 

It depends on how you've designed the view controller classes themselves. One way to design what you need would be to set the navigation bar type (i.e. colour) when you create the view controller, before you push it on the stack. Something like:

SomeViewController* someViewController = [[SomeViewController alloc] initWithNibName:@"SomeView" bundle:nil];
someViewController.navigationBarStyle = NBStyleRed; // NBStyleRed defined as an enum somewhere
[self.navigationController pushViewController:someViewController animated:YES];
[someViewController release];

The setter method for navigationBarStyle would then (re)create an appropriately-coloured navigation bar for the view controller.

Shaggy Frog