2011-09-22 82 views
0

如何觸發navigationController:willShowViewController委託方法爲我的實現下面,以便導航控制器中的所有視圖控制器將符合colorWithHexString#faf6f5?如何觸發navigationController:willShowViewController委託在AppDelegate中的方法

目前,我的FirstViewController將會顯示,但它似乎沒有調用委託方法來改變其導航欄的顏色(以及隨後堆疊到導航控制器上的所有其他視圖控制器)。請注意,我已將「UINavigationControllerDelegate」添加到我的應用程序委託頭文件中。

//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"]; 

} 

回答

0

是否有一個原因,您嘗試更改事件方法中的tintColor而不是創建UINavigationBar實例時的原因?

+0

那好吧我只想澄清,改變色調的顏色僅僅是我做定製的一個,我需要。更改導航欄中的文本顏色,並且似乎無法直接在UINavigationbar實例中執行此操作,因此我必須在事件方法中執行此操作 – Zhen

0

以下是您的操作方法。 (注意的UIColor不接受十六進制值,你應該使用RGB值,或檢查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; 
} 
相關問題