Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Present Viewcontroller getting black screen

I am trying present ViewController I have created with 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 getting it with black screen. What could be the issue?

like image 510
Anton Avatar asked Jan 19 '15 10:01

Anton


1 Answers

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

Here view controller does not load its view that's why you are getting black screen. Use storyboard object and identifier of view controller to load its view.

Specify storyboard identifier in Storyboard of AuthViewController controller.

Add Storyboard ID and mark true for Use Storyboard ID option like in below image:

enter image description here

Now get AuthViewController controller object using below code:

AuthViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"AuthViewController"];
like image 54
Kampai Avatar answered Oct 12 '22 07:10

Kampai