UISplitViewController will not display a modal view controller

I need to present a modal view controller before displaying a controller with a split view. I need this because the user will have to log in.

I read the answers in this forum, suggesting that the modal view controller be presented from AppDelegate, but nothing happens when I try to do this.

I installed my view controller in the same storyboard as the rest of my interface, and I gave the view controller the loginViewController identifier. I am trying to show a view controller in AppDelegate as follows:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { UISplitViewController *splitViewController = (UISplitViewController *) self.window.rootViewController; UINavigationController *navigationController = splitViewController.viewControllers.lastObject; splitViewController.delegate = (id) navigationController.topViewController; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; LoginViewController *lvc = (LoginViewController *) [storyboard instantiateViewControllerWithIdentifier:@"loginViewController"]; lvc.modalPresentationStyle = UIModalPresentationFullScreen; [splitViewController presentModalViewController:lvc animated:YES]; } [_window makeKeyAndVisible]; return YES; } 

When I do this, nothing happens. No errors, no modal representation controller, nothing. The app just shows my split view controller.

Can someone tell me how can I show the modal view controller before displaying the controller with split view?

+4
source share
2 answers

The view controller does not allow you to click / attend to another view manager, until and until the view is fully loaded.

Simply put, we will not let presentModalViewController / pushViewController be called in viewcontroller viewDidLoad / viewWillAppear. we must call this in viewDidAppear.

I had the same problem you were talking about.

Some solution I can say

Loads the LoginViewController after [self.window makeKeyAndVisible]; and in performSelctor (maybe with a delay). Move the code to display the LoginViewController in the ViewView DetailView DetailView.

thanks,

Naven Shan

+6
source

Instead of doing this in AppDelegate.m, do this in DetailViewController:

 LogInViewController *logInVC = [[LogInViewController alloc] init]; [self presentModalViewController:logInVC animated:NO]; 

This works for me.

+1
source

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


All Articles