presentViewController显示黑色页面
- (IBAction)submitButtonClicked:(id)sender{
NSLog(@"here");
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init];
[self presentViewController:sfvc animated:NO completion:NULL];
}
我想在用户点击应用程序中的提交按钮时打开一个新页面。但是,这会打开一个完全黑屏,没有任何东西。我如何让它打开viewController呢?presentViewController显示黑色页面
你是不是用户界面输入笔尖名称:
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];
对于故事板iOS7
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
斯威夫特
var next = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! DashboardController
self.presentViewController(next, animated: true, completion: nil)
不要忘记设置的ViewController StoryBoard Id
在StoryBoard
- >identity inspector
柜面其他人认为这,请确保您没有设置self.view.backgroundColor = UIColor.clearColor()
在视图中显示...这解决了它我。
嘿,这也解决了我的问题。谢谢。我知道解决方案应该是一个简单的解决方案,但不知道究竟是什么问题。 – mythicalcoder 2016-06-20 13:31:04
对,你需要关心'模态表现风格'https://developer.apple.com/reference/uikit/uiviewcontroller/1621355-modalpresentationstyle – onmyway133 2017-03-27 07:38:42
在添加和删除故事板中的视图控制器并忘记使用最新的故事板标识符更新视图控制器后,我遇到过这种情况。
例如,如果以编程方式移动到一个新的视图控制器,这样(代码音符标识符是“FirstUserVC”):
let firstLaunch = (storyboard?.instantiateViewControllerWithIdentifier("FirstUserVC"))! as UIViewController
self.navigationController?.pushViewController(firstLaunch, animated: true)
在此陈述中缺少“=”:SuccessOrFailViewController * sfvc [storyboard instantiateViewControllerWithIdentifier:@“SuccessOrFailViewController”]; – mikemike396 2013-08-08 02:11:13
编辑答案并修复它。 Thx – Lefteris 2013-08-08 06:17:29
使用故事板的方法非常酷! Thaks – pash3r 2014-01-31 11:09:15