[英]Can't push to View Controller from AppDelegate without losing Navigation Bar and Tab Bar setup iOS
I try to push to specific view controller from app delegate without losing previously set navigation bar and tab bar items setup. 我尝试从app delegate推送到特定的视图控制器,而不会丢失先前设置的导航栏和标签栏项目设置。
As presented in my Main storyboard: 如我的主故事板中所示:
After 1 action performed in TypeNameVC, on app relaunch I want to skip LogInVC and TypeNameVC in didFinishLaunchingWithOptions
in AppDelegate forward to MapViewController or any other VC of Tab Bar Controller. 在TypeNameVC中执行1次操作后,在应用程序重新启动时,我想跳过AppDelegate中
didFinishLaunchingWithOptions
中的LogInVC和TypeNameVC转发到MapViewController或任何其他标签栏控制器的VC。
This code initializes new Navigation Controller with new Navigation Bar and Tab Bar Controller is missing. 此代码使用新的导航栏初始化新的导航控制器,并且缺少标签栏控制器。
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
//To instantiate Main.storyboard.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//To instantiate VC to go to.
MapViewController *mapVC = (MapViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MapViewControllerID"];
//To push to instantiated VC.
[navigationController pushViewController:mapVC animated:YES];
I tried to performSegue
using segue to Tab Bar Controller but on Navigation Controller stack there is only LoginViewController (I checked it with [navigationController viewControllers]
) 我试图
performSegue
使用SEGUE到标签栏控制器,但在导航控制器栈只有LoginViewController(我检查了它[navigationController viewControllers]
I read through entire Stack Overflow, I made dozens of combinations but I can't figure out the solution. 我阅读了整个Stack Overflow,我做了几十个组合,但我无法弄清楚解决方案。 I would appreciate any help/advice.
我将不胜感激任何帮助/建议。
UPDATED QUESTION Screen: screen 更新的问题屏幕: 屏幕
Have a look to the screen image. 看看屏幕图像。 First row of screen shows how it looks like if I navigate "normally".
第一行屏幕显示了如果我“正常”导航它的样子。 Second row shows what happens if I push to MapVC from AppDelegate.
第二行显示如果我从AppDelegate推送到MapVC会发生什么。 What I need is to skip first two VC's with maintaining Navigation and Tab Bar bars setup.
我需要的是在保持导航和标签栏设置的情况下跳过前两个VC。
When I navigate "normally" Tab Bar Controller and it's VC's get correctly allocated. 当我导航“正常”标签栏控制器并且它的VC被正确分配。
2016-06-08 12:37:44.394 Checkpoint[4196:1034786] Navigation Controller VC's: ( LogInViewController: 0x135d50b00, 2016-06-08 12:37:44.394 Checkpoint [4196:1034786]导航控制器VC的:(LogInViewController:0x135d50b00,
TypeNameViewController: 0x135f455b0, TypeNameViewController:0x135f455b0,
UITabBarController: 0x135f1d180 UITabBarController:0x135f1d180
) )
2016-06-08 12:37:44.394 Checkpoint[4196:1034786] Tab Bar Controller VC's: ( 2016-06-08 12:37:44.394 Checkpoint [4196:1034786] Tab Bar Controller VC :(
MapViewController: 0x137078cf0, MapViewController:0x137078cf0,
PlacesTableViewController: 0x135f1d7d0, PlacesTableViewController:0x135f1d7d0,
FriendsTableViewController: 0x137083350 FriendsTableViewController:0x137083350
) )
When I push directly to MapVC they don't. 当我直接推送到MapVC时,他们没有。 I do get the point what's going on but I know how to code that solution.
我确实知道发生了什么,但我知道如何编写该解决方案。
Navigation Controller VC's: ( 导航控制器VC :(
LogInViewController: 0x15fd5ccf0, LogInViewController:0x15fd5ccf0,
MapViewController: 0x15fd6ffa0 MapViewController:0x15fd6ffa0
) )
2016-06-08 12:31:53.813 Checkpoint[4187:1033755] Tab Bar Controller VC's: (null) 2016-06-08 12:31:53.813 Checkpoint [4187:1033755] Tab Bar Controller VC :( null)
Customize your class MapViewController for visible Navigation Bar and Tab Bar : 为可见的导航栏和标签栏自定义MapViewController类:
- (instancetype)init
{
// init code
self.hidesBottomBarWhenPushed = NO;
retur self;
}
-(void)viewWillAppear:(BOOL)animated
{
// some code
[self.navigationController setNavigationBarHidden:NO];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.