xcode presentViewController 显示黑页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15621619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
presentViewController shows black page
提问by Ashish Agarwal
- (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 呢?
回答by Lefteris
You are not entering the nib name for the user Interface:
您没有为用户界面输入笔尖名称:
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];
回答by Mojtabye
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 Id
在StoryBoard
-> 中设置 ViewControlleridentity inspector
回答by Byron Coetsee
Incase anyone else finds this, make sure you haven't set self.view.backgroundColor = UIColor.clearColor()
in the view to be shown... This solved it for me.
如果其他人发现了这一点,请确保您没有self.view.backgroundColor = UIColor.clearColor()
在要显示的视图中进行设置...这为我解决了这个问题。
回答by D. Rothschild
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.
在故事板中添加和删除视图控制器并忘记使用最新的故事板标识符更新视图控制器后,我发生了这种情况。
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 中您有这样的 Storyboard ID 设置,其中 FirstUserVC 列在 Storyboard ID 的 Identity 中:
回答by mghersi
For Storyboard iOS7
对于故事板 iOS7
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];