如何在AppDelegate中触发navigationController:willShowViewController委托方法
如何为下面的实现触发 navigationController:willShowViewController 委托方法,以便导航控制器中的所有视图控制器都符合 colorWithHexString #faf6f5?
目前,我的 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"];
}
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"];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试在事件方法中而不是在创建 UINavigationBar 实例时更改tintColor 是否有原因?
is there a reason why you are trying to change the tintColor in an event method rather than when the UINavigationBar instance is created?
操作方法如下。 (请注意,UIColor 不接受十六进制值;您应该使用 RGB 值,或检查 此页。
Here's how you do it. (Note that UIColor doesn't accept hex values; you should use an RGB value, or check this page.