ViewController view from AppDelegate using UITabBarController design

My application is developed using UITabBarController and im trying to present a view on top of this (login screen) from the application delegate. When I use the following code:

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; tabBarController = [[UITabBarController alloc] initWithNibName:@"Main_TabBarController" bundle:nil]; self.window.rootViewController = tabBarController; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil]; Login_ViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"Login_ViewController"]; [self.window.rootViewController presentViewController:lvc animated:YES completion:nil]; 

I get an error message Warning: Attempt to present <Login_ViewController: 0x716fac0> on <UITabBarController: 0x7165240> whose view is not in the window hierarchy! , and the screen is just black. How to add Login_ViewController to the window hierarchy?

+3
source share
2 answers

You can always grab the current root view manager and use it to represent your login controller.

 UIViewController *presentingController = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; [presentingController presentViewController:viewController animated:YES completion:nil]; 

In addition, depending on how I want my login screen to look, I will push the login controller using the UIModalPresentationFormSheet.

 viewController.modalPresentationStyle = UIModalPresentationFormSheet; 
+3
source

You use two different mechanisms to create the user interface. You must move the tab bar controller to the storyboard. When you instantiate your storyboard, it overwrites your window with the new instance and the first controller as the root controller.

The error message reports that the tab bar controller view is not in the view hierarchy, and not vice versa.

I would create a controller with a view consisting only of your application logo, and inside this controller it will determine if you need to go to the login screen or not (if you have permanent logins). Then from the login screen go to the tab bar controller.

If the storyboard you are downloading is not the main storyboard, you do not need to download it manually. You should be able to configure the storyboard as the main one for the application, and iOS will automatically download it.

0
source

Source: https://habr.com/ru/post/900200/


All Articles