[英]How to trigger navigationController:willShowViewController delegate method in AppDelegate
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? 如何在以下实现中触发我的实现的navigationController:willShowViewController委托方法,以便导航控制器中的所有视图控制器都符合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). 当前,将显示我的FirstViewController,但它似乎并未调用委托方法来更改其导航栏的颜色(以及随后堆叠在导航控制器上的所有其他视图控制器的颜色)。 Note that I have already added the "UINavigationControllerDelegate" to my app delegate header file. 请注意,我已经将“ 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"];
}
为什么要尝试在事件方法中而不是在创建UINavigationBar实例时更改tintColor的原因?
Here's how you do it. 这是您的操作方式。 (Note that UIColor doesn't accept hex values; you should use an RGB value, or check this page . (请注意,UIColor不接受十六进制值;您应该使用RGB值,或检查此页面 。
- (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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.