presentViewController显示黑页

Ash*_*wal 16 xcode objective-c uikit ios ios6

- (IBAction)submitButtonClicked:(id)sender{
    NSLog(@"here");
    SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init];
    [self presentViewController:sfvc animated:NO completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)

我想在用户点击应用中的提交按钮时打开新页面.但是,这会打开完全黑屏,上面没有任何内容.如何让它打开viewController呢?

Lef*_*ris 43

您没有输入用户界面的nib名称:

SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] initWithNibName:@"SuccessOrFailViewController" bundle:nil];
[self presentViewController:sfvc animated:NO completion:NULL];
Run Code Online (Sandbox Code Playgroud)

对于故事板,这是要走的路:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:sfvc animated:YES];
Run Code Online (Sandbox Code Playgroud)


Moj*_*bye 8

迅速

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

不要忘记StoryBoard Id在StoryBoard- >中设置ViewControlleridentity inspector


Byr*_*see 5

如果其他人发现这一点,请确保您没有self.view.backgroundColor = UIColor.clearColor()在视图中设置显示...这为我解决了.