ios - uinavigationcontroller 在 iOS 中恢复状态时失去色彩

标签 ios objective-c cocoa-touch cocoa

我在 View 确实加载方法中设置导航 Controller 的色调,如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];
    UINavigationController *navigationController = [self navigationController];
    navigationController.navigationBar.barTintColor = [UIColor redColor];
}

上面将我的导航栏设置为红色,没有问题。

当用户关闭应用程序并对应用程序的状态进行编码,然后重新打开应用程序并对状态进行解码时,导航栏将显示默认的白色。

状态恢复时正在调用 View 加载,但导航 Controller 为零。我猜这就是默认颜色回来的原因。

我已经在我的导航 Controller 以及正在更改颜色的 View Controller 上设置了恢复 ID。

有人知道我可以做什么来保持为导航 Controller 设置的红色吗?

最佳答案

这可能是由于在将 View Controller 添加为导航 Controller 的子 Controller 之前加载了 View 。

代替viewDidLoad,在didMoveToParentViewController:中实现代码,如下所示:

- (void)didMoveToParentViewController:(UIViewController *)parent
{
    [super didMoveToParentViewController:parent];

    UINavigationController *navigationController = (UINavigationController*)parent;
    navigationController.navigationBar.barTintColor = [UIColor redColor];
}

关于ios - uinavigationcontroller 在 iOS 中恢复状态时失去色彩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22571412/

相关文章:

iphone - NSNotification 未在 View Controller 中接收来自 appDelegate 的信息

ios - AFNetworking问题:serialization.response代码= -1011“请求失败:找不到(404)”

objective-c - KVO nsmutablearray 删除对象通知

ios - iPad 不遵守 Interface Builder 的 AutoLayout 约束

ios - 我如何以编程方式选择日期并显示在 FSCalendar 上

ios - 多次调用 UITableViewCell 中的禁用/启用 UIButton

ios - 如果我调出 UIActionSheet,如何使其中一个选项转到新 View ?

ios - 未加载 InHouse/Enterprise 应用程序的 Cocoa Touch 框架

objective-c - 继承在模拟器上工作,但在 Iphone 上不行!

ios - Swift Firebase UIRefreshControl 创建重复的帖子