简体   繁体   English

presentViewController显示黑页

[英]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 ? 如何让它打开viewController呢?

You are not entering the nib name for the user Interface: 您没有输入用户界面的nib名称:

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

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 不要忘记在StoryBoard设置ViewController StoryBoard Id - > identity inspector

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

For Storyboard iOS7 对于Storyboard iOS7

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

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. 我在故事板中添加和删除View Controller并忘记使用最新的Storyboard标识符更新View Controller后发生了这种情况。

For example, if you are programmatically moving to a new View Controller, like this (note Identifier in the code is "FirstUserVC"): 例如,如果您以编程方式移动到新的视图控制器,请注意(注意代码中的标识符是“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: 在Interface Builder中确保您使用在故事板ID标识中列出的FirstUserVC设置了如此设置的Storyboard ID: 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM