ios - 以编程方式推送 UINavigationController 后顶部栏不可见

标签 ios objective-c iphone uinavigationcontroller uinavigationbar

在 AppDelegate 中,我检查是否存在用户,如果存在,我通过使用此代码推送 NavigationController 来“跳过”两个 ViewController:

if(currentUser){

    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Test"];

    self.window.rootViewController = viewController;
    viewController.navigationController.navigationBarHidden = NO; // Tried this nothing happened.
    [self.window makeKeyAndVisible];

}
else{
    [PFUser enableAutomaticUser];
    [[PFUser currentUser] incrementKey:@"RunCount"];
    [[PFUser currentUser] saveInBackground];
    [[PFUser currentUser] fetch];


    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    UINavigationController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"firstView"];

    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];

}

所以 true 语句跳过两个 ViewController 并推送 UINavigationController。但是当它以这种方式显示时,没有顶部栏。

但是,如果没有用户,那么它将通过 segues 以“正常”方式继续到 UINavigationController,然后该栏可见。

我该如何解决这个问题?

谢谢!

最佳答案

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
 bundle:nil];
    UIViewController *viewController = [storyboard 
instantiateViewControllerWithIdentifier:@"Test"];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = nav;

关于ios - 以编程方式推送 UINavigationController 后顶部栏不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28101739/

相关文章:

c++ - Xcode 7 不使用 C++ 框架构建项目

ios - 从 tableview 中的一个单元格将 segue 推到两页

iphone - "initialiser element is not a compile-time constant"创建 GCD 队列时

iphone - 多点裁剪后的UIImage如何保存?

ios - 带有激活 key 的 iPhone 应用程序

ios - 如果我们在 Swift 中触摸 UITextView 之外的其他区域,如何关闭键盘

ios - 怎么把[[ivar keep] autorelease]转换成ARC?

ios - 向多个 ViewController 发送数据?

objective-c - 我的心理障碍——努力学习 Objective C

iphone - 删除重复的子目录后没有这样的文件或目录