Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

ios - How does Xcode load the main storyboard?

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]));

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?)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Look at your Target settings for the Project

enter image description here

Notice the Main Storyboard setting.

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...