IOS Present Viewcontroller gets a black screen

I am trying to introduce a ViewController created using StoryBoards:

AuthViewController *authViewController = [[AuthViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:authViewController]; UIViewController *vc = [[[[UIApplication sharedApplication] windows] firstObject] rootViewController]; [vc presentViewController:nav animated:YES completion:nil]; 

But get it with a black screen. What could be the problem?

+6
source share
4 answers

Alloc init AuthViewController does not mean that it will create a view layout for the controller.

Here, the view manager does not load its view of why you are getting a black screen. Use the storyboard object and view controller identifier to load its view.

Specify the storyboard ID in the Storyboard of the AuthViewController .

Add a Storyboard ID and check true for Use Storyboard ID , as shown below:

enter image description here

Now get the controller's AuthViewController object using the code below:

 AuthViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"AuthViewController"]; 
+13
source

Below is a snippet below for the storyboard:

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; AuthViewController *authViewController = [storyboard instantiateViewControllerWithIdentifier:@"**YOUR_STORYBOARD_ID**"]; [authViewController setModalPresentationStyle:UIModalPresentationFullScreen]; [self presentViewController:authViewController animated:YES completion:nil]; 
+4
source

Is the ViewController for the AuthViewController present in the Storyboard ? If so, you must pass it the Storyboard ID and initiate your AuthViewController as follows:

 AuthViewController *authViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"_STORYBOARD_ID_"]; 

Hope this helps.

+2
source

My problem was that the class, like AuthViewController in the storyboard, was a simple UIViewController, and in my quick class it was UITabBarController. That is why it did nothing.

Stupid mistake, but I hope I can save some time for someone.

0
source

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


All Articles