如何实例化(附加)故事板并将其推送到我的应用程序中?

How to instantiate and push an (additional) storyboard into my app?

我的应用主要是在没有故事板的情况下构建的。 但是,我只创建了一个用于用户注册。

这个故事板由一个包含 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;
}

注意: 我在标识符自定义 Class 部分将 FirstVC 场景设置为 FirstVC,并将故事板 ID 设置为 FirstVC。但是我还没有接触到 NavigationController 场景,我应该将自定义 class 设置为 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;
}