presentViewController shows black page

19,059

Solution 1

You are not entering the nib name for the user Interface:

SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] initWithNibName:@"SuccessOrFailViewController" bundle:nil];
[self presentViewController:sfvc animated:NO completion:NULL];

For storyboard this is the way to go:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:sfvc animated:YES];

Solution 2

Swift

var next = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! DashboardController
self.presentViewController(next, animated: true, completion: nil)

don't forget to set ViewController StoryBoard Id in StoryBoard -> identity inspector

Solution 3

Incase anyone else finds this, make sure you haven't set self.view.backgroundColor = UIColor.clearColor() in the view to be shown... This solved it for me.

Solution 4

For Storyboard iOS7

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];

Solution 5

I've had this happen after adding and deleting View Controllers in the Storyboard and forgetting to update the View Controller with the latest Storyboard identifier.

For example, if you are programmatically moving to a new View Controller, like this (note Identifier in the code is "FirstUserVC"):

let firstLaunch = (storyboard?.instantiateViewControllerWithIdentifier("FirstUserVC"))! as UIViewController
self.navigationController?.pushViewController(firstLaunch, animated: true)

The make sure in Interface Builder you have the Storyboard ID set like this with FirstUserVC listed in the Identity for Storyboard ID: enter image description here

Share:
19,059
Ashish Agarwal
Author by

Ashish Agarwal

Updated on June 09, 2022

Comments

  • Ashish Agarwal
    Ashish Agarwal almost 2 years
    - (IBAction)submitButtonClicked:(id)sender{
        NSLog(@"here");
        SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init];
        [self presentViewController:sfvc animated:NO completion:NULL];
    }
    

    I am trying to open a new page when a user clicks the submit button in the app. However, this opens completely black screen with nothing on it. How do I make it open the viewController instead ?

  • mikemike396
    mikemike396 almost 11 years
    Missing "=" in this statment: SuccessOrFailViewController *sfvc [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewC‌​ontroller"];
  • Lefteris
    Lefteris almost 11 years
    Edited the answer and fixed it. Thx
  • finneycanhelp
    finneycanhelp almost 9 years
    It's good that @Lefteris left the nib version in there too. It reminded me that nibs are still a viable option as well.
  • mythicalcoder
    mythicalcoder almost 8 years
    Hey, this solved my problem too. Thanks. I knew the solution should be a simple one, but don't know what exactly is the problem.
  • onmyway133
    onmyway133 about 7 years
    Right, you need to care about modal​Presentation​Style developer.apple.com/reference/uikit/uiviewcontroller/…
  • Alexey
    Alexey almost 6 years
    This is a great answer!