简体   繁体   English

从视图控制器返回后未更新UINavigationBar titleTextAttributes

[英]UINavigationBar titleTextAttributes not updated after coming back from a View Controller

I'm using a UINavigationController to display some view controllers. 我正在使用UINavigationController来显示一些视图控制器。 I need to change the color of the navigation bar title every time I switch between two view controllers. 每次在两个视图控制器之间切换时,都需要更改导航栏标题的颜色。 This is what I'm doing now: 这就是我现在正在做的:

First View Controller 第一视图控制器

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.navigationController.navigationBar.titleTextAttributes = 
         @{
              NSForegroundColorAttributeName: [UIColor whiteColor],
              NSFontAttributeName: [UIFont systemFontOfSize:14.0]
         };
}

Second View Controller 第二视图控制器

- (void)viewDidLoad:(BOOL)animated
{
    [super viewDidLoad:animated];

    self.navigationController.navigationBar.titleTextAttributes = 
         @{
              NSForegroundColorAttributeName: [UIColor blackColor],
              NSFontAttributeName: [UIFont systemFontOfSize:14.0]
         };
}

The first time I load First VC and when I push Second VC, the title color is handled correctly. 第一次加载First VC时,当我按Second VC时,标题颜色已正确处理。 The problem here is that when I pop from Second to First view controller, the title is still black, even if viewWillAppear is called correctly and, if I print self.navigationController.navigationBar.titleTextAttributes , the values seems to be updated ( NSForegroundColorAttributeName is white). 这里的问题是,当我从第二个视图控制器弹出到第一个视图控制器时,即使正确调用了viewWillAppear ,标题仍然是黑色的;如果我打印self.navigationController.navigationBar.titleTextAttributes ,则值似乎已更新( NSForegroundColorAttributeName为白色)。

Maybe because of the push/pop transition animation, values are not reflecting. 可能是由于推送/弹出过渡动画导致值未反映出来。 Try calling it this way. 尝试以这种方式调用它。

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    dispatch_async(dispatch_get_main_queue(), ^{
        self.navigationController.navigationBar.titleTextAttributes =
        @{
            NSForegroundColorAttributeName: [UIColor blackColor],
            NSFontAttributeName: [UIFont systemFontOfSize:14.0]
        };
    });
}    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在视图控制器中更改UINavigationBar titleTextAttributes更改整个UINavigationController的标题颜色 - Changing UINavigationBar titleTextAttributes inside view controller changing title color for entire UINavigationController 如何从第一个View控制器中出现的第二个UIView Controller中删除UINavigationBar label.text? - How to remove UINavigationBar label.text from second UIView Controller which is coming in first View controller? 获取UINavigationBar的默认titleTextAttributes - Getting the default titleTextAttributes for UINavigationBar 从另一个视图控制器返回时 UIScrollview 不起作用(弹出后) - UIScrollview not working when coming back from another view controller ( After pop) 从详细信息视图控制器返回时,SideBar菜单不起作用 - SideBar Menu is not working when it is coming back from the detail View Controller UIPresentation控制器-从后台返回后布局出错 - UIPresentation controller - layout going wrong after coming back from background 当我按下“后退”按钮时,从选项卡控制器中的选项卡推送的视图控制器未返回 - view controller pushed from tab in tabbar controller is not coming back when i press back button 导航回到上一个视图控制器 - Navigation coming back to the previous view controller UINavigationBar titleTextAttributes - 在过渡期间不应用 - UINavigationBar titleTextAttributes - not applied during transitions 推送视图控制器后,UINavigationBar颜色正在更改 - UINavigationBar color is getting change after pushing a view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM