我的应用程序主要是在没有情节提要的情况下构建的。
但是,我仅为用户注册创建了一个。
此情节提要包括一个包含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场景设置为FirstVC,还将情节提要ID设置为FirstVC。但是,我还没有接触过NavigationController的场景,应该将自定义类设置为UINavigationController吗?
最佳答案
您可以尝试添加此行吗
[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;
}