presentViewController显示黑页

时间:2013-03-25 18:01:15

标签: ios objective-c xcode ios6 uikit

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

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

5 个答案:

答案 0 :(得分:43)

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

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

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

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

答案 1 :(得分:8)

<强>夫特

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

不要忘记在StoryBoard Id - &gt;中设置ViewController StoryBoardidentity inspector

答案 2 :(得分:5)

如果其他人发现这一点,请确保您未在​​视图中设置self.view.backgroundColor = UIColor.clearColor()以便显示...这样就解决了这个问题。

答案 3 :(得分:1)

对于Storyboard iOS7

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

答案 4 :(得分:1)

我在故事板中添加和删除View Controller并忘记使用最新的Storyboard标识符更新View Controller后发生了这种情况。

例如,如果您以编程方式移动到新的视图控制器,请注意(注意代码中的标识符为&#34; FirstUserVC&#34;):

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

在Interface Builder中确保您使用在故事板ID标识中列出的FirstUserVC设置了如此设置的Storyboard ID: enter image description here