XCode如何加载主故事板? [英] How does XCode load the main storyboard?
问题描述
当我使用storyboard在XCode 4.6中创建一个新的单一视图应用程序时,我们可以看到main函数使用应用程序委托创建一个新的应用程序,如下所示:
When I create a new single view application in XCode 4.6 using storyboard, we can see that the main function creates a new application using the application delegate like this:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
但是,如果我们查看MyAppDelegate.h和MyAppDelegate.m,代码中没有任何地方可以引用MainStoryboard.storyboard。这与非故事板版本不同,我们可以找到以编程方式加载nib文件的代码行。
However if we look at MyAppDelegate.h and MyAppDelegate.m, there is nowhere in the code that references MainStoryboard.storyboard. This differs from a non-storyboard version where we can find the line of code that loads the nib file programmatically.
所以我的问题是,故事板是如何加载的? (我应该去哪里寻找它?)
So my question is, how does the storyboard get loaded? (where should I poke to find it?)
谢谢
推荐答案
查看项目的目标设置
注意主要故事板设置。
如果你想自己在代码中这样做,你会做类似的事情。
If you wanted to do this in code yourself, you would do something like.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *vc = [storyboard instantiateInitialViewController];
// Set root view controller and make windows visible
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
这篇关于XCode如何加载主故事板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!