Is it possible to change 'is initial view controller' based upon Target?

假如想象 提交于 2020-03-05 22:23:30

问题


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 #ifdefs 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!