0

How can I trigger the navigationController:willShowViewController delegate method for my implementation below so that all the view controllers in the navigation controller will conform to the colorWithHexString #faf6f5?

Currently, my FirstViewController will be displayed but it doesn't seem to call the delegate method to change the color of it's navigation bar (as well as for all other view controllers that are stacked onto the navigation controller subsequently). Note that I have already added the "UINavigationControllerDelegate" to my app delegate header file.

//In App Delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //Set First View
    FirstViewController *firstView = [[FirstViewController alloc]init];

    // pushes a nav con 
    UINavigationController *tempNavcon = [[UINavigationController alloc]initWithRootViewController:firstView];
    self.navcon = tempNavcon;

    [self.window addSubview:navcon.view];

}

- (void)navigationController:(UINavigationController *)navigationController 
  willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

    navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"#faf6f5"];

}
Zhen
  • 12,361
  • 38
  • 122
  • 199

2 Answers2

0

is there a reason why you are trying to change the tintColor in an event method rather than when the UINavigationBar instance is created?

John Carter
  • 2,056
  • 1
  • 17
  • 16
  • Oh ok just to clarify, changing tint color is only one of the customization I am doing. I needed to change the text color in the navigation bar as well and there seem to be no way of doing it directly in a UINavigationbar instance, hence I had to do it in an event method – Zhen Sep 23 '11 at 07:02
0

Here's how you do it. (Note that UIColor doesn't accept hex values; you should use an RGB value, or check this page.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //Initialize your view controller.
    FirstViewController * firstView = [[FirstViewController alloc] init];

    // Create an instance of a UINavigationController. Its stack contains only firstView.
    UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:firstView];

    //Here is where you set the color of the navigationBar. See my note above for using RGB.
    navController.navigationBar.tintColor = [UIColor greenColor];

    // You can now release the firstView here, navController will retain it
    [firstView release];

    // Place navigation controller's view in the window hierarchy
    [[self window] setRootViewController:navController];

    [navController release];

    [self.window makeKeyAndVisible];
    return YES;
}
Community
  • 1
  • 1
bryanjclark
  • 6,247
  • 2
  • 35
  • 68