Pushing a navigation controller is not supported- performing segues

后端 未结 4 989
庸人自扰
庸人自扰 2020-12-31 05:20

I created a new navigation controller in my storyboard (not programmatically!) and set it to be \"Root View Controller\" to a regular UIViewController and added a button in

4条回答
  •  鱼传尺愫
    2020-12-31 06:02

    I had the same trouble. I wanted to have a navigation controller on each storyboard, so that each could run independently, be individually debugged, and so that the look would be right with the navigation bar.

    Using other approaches, I found the UINavigationController would be retained from the original storyboard -- which I didn't want -- or I'd get errors.

    Using the AppDelegate in your view controller to set the rootViewController worked for me (borrowing segue naming conventions from Segue to another storyboard?):

    - (void)showStartupNavigationController {
    NSLog(@"-- Loading storyboard --");
    
    //Get the storyboard from the main bundle.
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Startup" bundle:nil];
    //The navigation controller, not the view controller, is marked as the initial scene.
    UINavigationController *theInitialViewController = [storyBoard instantiateInitialViewController];
    
    NSLog(@"-- Loading storyboard -- Nav controller: %@", theInitialViewController);
    
    //Remove the current navigation controller.
    [self.navigationController.view removeFromSuperview];
    UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
    window.rootViewController = theInitialViewController;
    

提交回复
热议问题