Instead of Push Segue How to Replace View Controller (Or Remove from Navigation Stack)

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

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)

In swift

override func perform() {
if let navigationController = self.source.navigationController {
navigationController.setViewControllers([self.destination], animated: true)
}
}

Remove view controller from navigation stack after push segue (using Storyboard segues)

Just replace the rootViewController of your UIWindow.
controllerA and controllerB can be any Viewcontroller-Class you want.

You could use a simple UITableViewController for the Loginpage and then replace the rootViewController of your UIWindow with a UINavigationController holding controllerB

[UIView transitionFromView:controllerA.view
toView:controllerB.view
duration:0.65f
options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionCrossDissolve)
completion:^(BOOL finished){
delegate.window.rootViewController = controllerB;
}];

how to perform push segue to certain view controller in navigation stack in the different storyboard?

Create a reference id for the ViewController you want to push

In the second storyboard

Choose the ViewController on the interface builder

Assign "Storyboard ID" to it (for ex. SecondVC)

Back to the main storyboard

choose the storyboard reference to the "second" storyboard and add the VC id (SecondVC) in the "Referenced ID" field

How to Dismiss Model View Controller before push?

I think you can implement in that way:

  • when you at screen 3 you want push screen 2. You will dismiss screen 3 and call a delegate back screen 1.
  • And from screen1 you will push view to screen2.

You can see my demo for my idea: Demo Pushview Swift

DemoPushViewObj

How to detect whether show (push) segue navigation controller is pressed?

You can work on the viewWillDisappear method on your second view controller like this:

- (void)viewWillDisappear:(BOOL)animated
{
if(self.isMovingFromParentViewController){
NSLog(@"Controller being popped");
}
}

In this case, self.isMovingFromParentViewController will be true if the controller is being popped.

You can also check for self.isMovingToParentViewController on viewWillAppear for example, to check that the controller is being pushed.

Also self.isBeingDismissed and self.isBeingPresented are available and refer to when a controller is being presented/dismissed (modally).



Related Topics



Leave a reply



Submit