Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 312
Ashish Agarwal Avatar asked Mar 25 '13 18:03

Ashish Agarwal


3 Answers

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];
like image 91
Lefteris Avatar answered Nov 10 '22 02:11

Lefteris


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

like image 25
Mojtaba Yeganeh Avatar answered Nov 10 '22 03:11

Mojtaba Yeganeh


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.

like image 26
Byron Coetsee Avatar answered Nov 10 '22 03:11

Byron Coetsee