我正在听从 this question 的建议为了在运行时定义我的初始 View Controller ,而不是总是基于 Storyboard 属性相同。
这是我的didFinishLaunching
方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *compactNavigationController = [mainStoryboard instantiateViewControllerWithIdentifier:@"CompactNavigationController"];
self.window.rootViewController = compactNavigationController;
[self.window makeKeyAndVisible];
CompactPostsViewController *controller = (CompactPostsViewController *)compactNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
并且我在我的 Storyboard 中取消选中“Is Initial View Controller”,并从我的应用程序信息中的默认 Storyboard 中删除了“Main”。
但是当我启动该应用程序时,我得到一个完全黑屏。我做错了什么?
最佳答案
您的窗口为零,因为您从未创建过它。你需要添加这一行,
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
当您的 info.plist 中有“主 Storyboard 基本名称”条目时,会为您创建该窗口,但如果您删除了该条目,则您必须自己创建窗口。
关于ios - 为什么我无法在我的 AppDelegate 中以编程方式更改我的初始 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23074649/