在 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/