如何在我的实现中触发navigationController:willShowViewController委托方法,以便导航控制器中的所有视图控制器都符合colorWithHexString#faf6f5?
目前,我的FirstViewController将会显示,但它似乎没有调用委托方法来更改它的导航栏的颜色(以及随后堆叠到导航控制器上的所有其他视图控制器)。请注意,我已将“UINavigationControllerDelegate”添加到我的app delegate头文件中。
//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 :(得分:0)
您是否有理由尝试在事件方法中更改tintColor而不是在创建UINavigationBar实例时?
答案 1 :(得分: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;
}