xcode 以编程方式在委托中调用故事板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9828217/
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
Programmatically call storyboard in delegate
提问by RockBaby
I'm trying to programmatically call my storyboard. My storyboard consists of the following:
我正在尝试以编程方式调用我的故事板。我的故事板包括以下内容:
[Navigation Controller] -> [MainMenuView] -> [DetailsView]
[导航控制器] -> [MainMenuView] -> [DetailsView]
The "MainMenu" identifier was placed in the [MainMenuView]
“MainMenu”标识符被放置在 [MainMenuView] 中
The problem i'm having is the screen showing blank. What do i need to do?
我遇到的问题是屏幕显示空白。我需要做什么?
Thanks.
谢谢。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MainMenuView *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainMenu"];
return YES
}
回答by sarfata
You need to first create the window manually and then add the rootViewController in it (the previous answer was almost correct):
您需要先手动创建窗口,然后在其中添加rootViewController(之前的答案几乎是正确的):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *mainViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
回答by jonkroll
You need to set the rootViewController property of your application's window:
您需要设置应用程序窗口的 rootViewController 属性:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MainMenuView *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainMenu"];
self.window.rootViewController = rootViewController;
return YES;
}