Error: Manually adding the rootViewController's view to the view hierarchy is no longer supported

Viewed 2586

I upgraded to Xcode 11.1 and trying to compile an older Objective C app that programmatically sets the rootViewController.

How do I work around this error?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    lvc = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
    nav = [[UINavigationController alloc] initWithRootViewController:lvc];

    nav.navigationBar.barTintColor = [UIColor whiteColor];

    self.window.rootViewController = nav;
    [self.window addSubview:nav.view];

    return YES;
}
1 Answers

See the line [self.window addSubview:nav.view];? Delete it. It was always wrong.

Related