如何 不 使用虚拟初始视图控制器
确保所有初始视图控制器都有一个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 basename。在
General标签上,清除的值
Main Interface。这将删除警告。
在应用程序委托的
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;}


