presentViewController显示黑色页面
- (IBAction)submitButtonClicked:(id)sender{ NSLog(@"here"); SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init]; [self presentViewController:sfvc animated:NO completion:NULL]; }
我试图打开一个新的页面,当用户点击提交button在应用程序。 但是,这完全打开了黑屏,没有任何东西。 我如何让它打开viewController呢?
您没有input用户界面的笔尖名称:
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];
迅速
var next = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! DashboardController self.presentViewController(next, animated: true, completion: nil)
不要忘记在StoryBoard
– > identity inspector
设置ViewController StoryBoard Id
Incase其他人发现这一点,请确保你没有设置self.view.backgroundColor = UIColor.clearColor()
在视图中显示…这解决了我。
对于Storyboard iOS7
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"]; [sfvc setModalPresentationStyle:UIModalPresentationFullScreen]; [self presentViewController:sfvc animated:YES completion:nil];
在添加和删除故事板中的视图控制器并忘记使用最新的故事板标识符更新视图控制器后,我遇到过这种情况。
例如,如果以编程方式移动到新的视图控制器,就像这样(注意代码中的标识符是“FirstUserVC”):
let firstLaunch = (storyboard?.instantiateViewControllerWithIdentifier("FirstUserVC"))! as UIViewController self.navigationController?.pushViewController(firstLaunch, animated: true)
确保在界面生成器中,您已经将Storyboard ID设置为与Storyboard ID标识中列出的FirstUserVC类似: