是否可以根据 Target 更改“是初始视图控制器"吗? [英] Is it possible to change 'is initial view controller' based upon Target?

查看:24
本文介绍了是否可以根据 Target 更改“是初始视图控制器"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 iOS 产品,它有几个不同的 SKU,每个 SKU 都应该从不同的视图控制器开始.我有由目标分隔的不同 SKU,这允许我指定该产品版本所需的预处理器.

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.

但是,我希望能够做的一件事是更改 Storyboard 中的是初始视图控制器"值,以便构建不同的 SKU,而无需手动选中该框,具体取决于我正在建造的东西.

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.

所以我的问题是,这可以通过目标来完成,还是以编程方式完成(所以我可以使用带有特定 SKU 预处理器的 #ifdef 来完成)?

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

提前致谢!

推荐答案

您必须使用故事板中分配的标识符在代码中执行此操作.您可以创建目标定义头文件或在 AppDelegate.m 的开头执行 #ifdefs:

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"
[...]

然后在您的应用程序委托的 application:didFinishLaunchingWithOptions: 中,您可以执行以下操作:

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;

这要求您从项目的 Info.plist 中删除任何Main storybaord"引用,以便 UIKit 默认不会加载它.

this requires you to remove any "Main storybaord" reference from the project's Info.plist so UIKit won't load it by default.

这篇关于是否可以根据 Target 更改“是初始视图控制器"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆