如何以编程方式InitialViewController为情节提要设置?我想根据不同的启动条件将情节提要板打开到其他视图。
InitialViewController
如何 不 使用虚拟初始视图控制器
确保所有初始视图控制器都有一个Storyboard ID。
在情节提要中,取消选中第一个视图控制器中的“是初始视图控制器”属性。
如果您此时运行应用程序,则将阅读:
Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?
您会注意到,应用程序委托中的window属性现在为nil。
在应用程序的设置中,转到目标和Info选项卡。有明确的价值Main storyboard file base name。在General标签上,清除的值Main Interface。这将删除警告。
Info
Main storyboard file base name
General
Main Interface
在应用程序委托的application:didFinishLaunchingWithOptions:方法中创建窗口和所需的初始视图控制器:
application:didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:<storyboard id>]; self.window.rootViewController = viewController; [self.window makeKeyAndVisible]; return YES; }