我的应用主要是在没有故事板的情况下构建的。 但是,我只创建了一个用户注册。
此故事板由包含2个视图控制器的导航控制器组成。 第一个被称为“FirstVC”,一个被称为“SecondVC”(这个不会用于我的问题)。
我正在尝试将其推送到AppDelegate.m文件中(尝试各种方式,见下文)但我的屏幕始终是黑色的。
尝试1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:@"FirstVC"];
UINavigationController *navController =(UINavigationController *)self.window.rootViewController;
[navController pushViewController:fvc animated:YES];
return YES;
}
尝试2
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:@"FirstVC"];
self.window.rootViewController = fvc;
return YES;
}
注意:我已将FirstVC场景设置为标识符Custom Class部分中的FirstVC,并将故事板ID设置为FirstVC。但是我没有触及NavigationController场景,我应该将自定义类设置为UINavigationController吗?
答案 0 :(得分:1)
你可以尝试添加这一行吗
[self.window makeKeyAndVisible];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:@"FirstVC"];
self.window.rootViewController = fvc;
[self.window makeKeyAndVisible]; //**Add this**
return YES;
}