Search code examples
iosobjective-cxcodeios6uikit

presentViewController shows black page


- (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 ?


Solution

  • 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];