Instead of push segue how to replace view controller (or remove from navigation stack)?

前端 未结 14 881
眼角桃花
眼角桃花 2020-11-28 01:46

I have a small iPhone app, which uses a navigation controller to display 3 views (here fullscreen):

\"Xcode

14条回答
  •  独厮守ぢ
    2020-11-28 02:49

    You could use a custom segue: to do it you need to create a class subclassing UIStoryboardSegue (example MyCustomSegue), and then you can override the "perform" with something like this

    -(void)perform {
        UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
        UIViewController *destinationController = (UIViewController*)[self destinationViewController];
        UINavigationController *navigationController = sourceViewController.navigationController;
        // Pop to root view controller (not animated) before pushing
        [navigationController popToRootViewControllerAnimated:NO];
        [navigationController pushViewController:destinationController animated:YES];    
    }
    

    At this point go to Interface Builder, select "custom" segue, and put the name of your class (example MyCustomSegue)

提交回复
热议问题