问题
I have an iOS product that has a couple of different SKUs, each of which should start with a different view controller. I have the different SKUs separated by Targets, which allows me to specify the preprocessors required for that version of the product.
The one thing I would like to be able to do, however, is to alter the 'is initial view controller' value in the Storyboard in order to build the different SKUs without having to manually check the box on or off depending upon what I am building.
So my question is, can this be done either by target, or programatically (so I can do this using an #ifdef with the particular SKU preprocessors)?
Thanks in advance!
回答1:
you have to do it in code using identifiers assigned in the storyboard. you can create a target-definition header file or do #ifdef
s at the beginning of your AppDelegate.m:
#ifdef TARGET_FOO
#define INITIAL_VC_ID @"FOO_ID"
[...]
and then in your app delegate's application:didFinishLaunchingWithOptions:
you can do:
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
[window setRootViewController:[mainStoryboard instantiateViewControllerWithIdentifier:INITIAL_VC_ID]];
[window makeKeyAndVisible];
return YES;
this requires you to remove any "Main storybaord" reference from the project's Info.plist so UIKit won't load it by default.
来源:https://stackoverflow.com/questions/15191167/is-it-possible-to-change-is-initial-view-controller-based-upon-target