How can I pop a view from a UINavigationController and replace it with another in one operation?

后端 未结 16 2205
谎友^
谎友^ 2020-11-27 10:01

I have an application where I need to remove one view from the stack of a UINavigationController and replace it with another. The situation is that the first view creates an

16条回答
  •  半阙折子戏
    2020-11-27 10:36

    If you want to show any other view controller by popToRootViewController then you need to do following:

             UIViewController *newVC = [[WelcomeScreenVC alloc] initWithNibName:@"WelcomeScreenVC" bundle:[NSBundle mainBundle]];
                NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
                [viewControllers removeAllObjects];
                [viewControllers addObject:newVC];
                [[self navigationController] setViewControllers:viewControllers animated:NO];
    

    Now, all your previous stack will be removed and new stack will be created with your required rootViewController.

提交回复
热议问题