我使用Storyboards
创建了我的项目。根ViewController
位于一个Storyboard
中,我在appDelegate
中没有编写任何代码。
现在我想展示一下我的应用程序,所以我想将根ViewController
从Tab Bar
更改为我的TourVC,当应用程序的导览完成后,我想再次将根ViewController
切换回Tab Bar
。
因此,我在网上查找并按照以下步骤进行操作:
1)从app.plist文件中删除Storyboards
,
2)取消选中Storyboards
中“isInitialViewController”选项,在Tab Bar
控制器的情况下检查它,因为它是一个根ViewController
,
3)将此代码添加到appDelegate.m文件中。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ProductTourViewController *PT = [[ProductTourViewController alloc] initWithNibName:@"ProductTourViewController" bundle:nil];
self.window.rootViewController = PT;
[self.window makeKeyAndVisible];
return YES;
但是我的应用程序在运行时崩溃,出现以下错误日志:
[ProductTourViewController selectedViewController]: unrecognized selector sent to instance 0x1766a9e0
同时我也收到了一个警告,
Unsupported Configuration: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.
didFinishLaunchingWithOptions
方法中应用程序尚未设置 keyWindow,因此在这种情况下应该使用self.window.rootViewController = ...
。 - Anton Gaenko