How to pop from one view controller to another view controller

Using iOS I Have 15 ViewControllers now I want to pop from one ViewController to another View Controller.

I am using this code:

SecondViewController *Sec=[SecondViewController alloc]init];
[self.navigationController popViewController:Sec animated:YES];

This shows error this ViewController not exist and then I am using this code:

NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];

This code is right to pop from thirdViewController to secondViewController. But What happened when we pop from Ninth(9th)ViewController to Fifth(5th)ViewController then I am using this code in Ninth(9th)ViewController:

NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:4] animated:YES];

It does not pop from Ninth(9th)ViewController to Fifth(5th)ViewController apart that it pops Ninth(9th)ViewController to Eight(8th)ViewController. I don't know what happened when we use this line:

NSArray *array = [self.navigationController viewControllers];
NsLog(@"array = %@",array);

When we use this in Ninth(9th)ViewController. NsLog shows:

array=   First(1st)ViewController;  
         Second(2nd)ViewController;
         Eight(8th)ViewController;
         Ninth(9th)ViewController;

I don't know why only Four View Controllers show. Whenever I am using 15 View Controllers. This problem occurs in each view controller. For instance if I am Using pop form fifteenth(15th)ViewController to Fifth(5th)ViewController then same problem manifests.

NSArray *array = [self.navigationController viewControllers];
NsLog(@"array = %@",array);

array=     First(1st)ViewController;  
           Second(2nd)ViewController;
           fourteenth(14th)ViewController;
           fifteenth(15th)ViewController;

I want to count Number of ViewControllers and then pop to specific ViewController.

Swift 4.0 - Swift 5.0

 for controller in self.navigationController!.viewControllers as Array {
            if controller.isKind(of: HomeViewController.self) {
                self.navigationController!.popToViewController(controller, animated: true)
                break
            }
        }

popViewController(animated:), the transition. Pass false if you are setting up a navigation controller before its view is displayed. In other words, you cannot pop the last item on the stack. A tutorial explaining how to pass data forward from one view controller to another view controller using a segue.

You can't pop to a new view controller (like you do with your secondViewController example).

When using a UINavigationController you

Add Controller to the stack with:

[self.navigationController pushViewController:<yournewViewController> animated:YES];

Pop to the previous one with :

[self.navigationController popViewControllerAnimated:YES];

Pop to a previous controller in the stack (Must have been pushed before) :

[self.navigationController popToViewController:<ViewControllerToPopTo> animated:YES];

Go back to the root Controller with

[self.navigationController popToRootViewControllerAnimated:YES];

Showing and Hiding View Controllers, A segue is a visual representation of a transition from one view controller to another. A segue starts with an action such as a button tap or table-row selection in the� I am trying to send some data from one view controller to another. But I can't seem to get this code to work! It should change a label to a variable that was passed to it but it doesn't change anything. ViewController.swift

for (UIViewController *controller in self.navigationController.viewControllers)
        {
            if ([controller isKindOfClass:[nameOfYourViewControllerYouWantToNavigate class]])
            {
                [self.navigationController popToViewController:controller animated:YES];

                break;
            }
        }

View Controllers for iOS & Swift – LearnAppMaking, In the next section, we'll discuss how a view controller fits within the larger architecture of your app. Learn how to build iOS apps. Get started with� In my case im using a Master Details view ( Split View Controller ). My details view controller is embedded inside an navigation controller. So when i wanted to dismiss my Details view controller. I had to pop it from the navigation controller of the parent (Split view controller) Like this.

Try this

 [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];

How to move from one view controller to another view controller , Method #1 (simple): In your storyboard file, select the button you would like to present the second view controller, right click and drag (you should see a line� There are two controllers are there; One is Login Controller and the second one is Home Controller. From Login Controller, I have to pass UserNameof the Login Person to the view Page. Login Controller redirect to Another controller called Home Controller.From there I have to pass that value to the view page.

First:

 SecondViewController *Sec=[SecondViewController alloc]init];
 [self.navigationController popViewController:Sec animated:YES];

You can’t do this because you allocate a new Sec view controller that’s not in a navigation controller.

Consider using this:

You are in 9 view controller

for (int i= 0 ; i < [[self.navigationController viewControllers]count] ; i++) {
    if ( [[[self.navigationController viewControllers] objectAtIndex:i] isKindOfClass:[FifiViewControllerClassname class]]) {
        [self.navigationController popToViewController:[array objectAtIndex:i] animated:YES];
    }
}

Managing View Controllers With Container View Controllers, You can push and pop view controllers onto and from a navigation stack. A container view controller manages a view just like any other� There are various ways to pass data from a Controller to a View. I'm going to discuss how Controllers interact with Views and specifically cover ways you can pass data from a Controller to a View to render a response back to a client. So, let's get started. ViewBag ViewBag is a very well known way to pass the data from Controller to View & even

Pushing, Popping, Presenting, & Dismissing ViewControllers, This is why it is not possible to call popViewController on a I realized how important it is to fully understand the different navigation patterns. mvc view results: return View() - will return a view named the same as the action method from the corresponding path of the controller HomeContoller and Action Index will look in ~/Views/Home/ and ~/Views/Shared/ for Index.cshtml or Index.vbhtml

Pop to specific view controller ios swift, That is what enables a child view controller in a navigation stack to push another view controller onto or to pop itself from the navigation stack. Add button actions� When you switch from one view controller to the next, with a navigation controller for instance, you make a segue. In your view controller, you can hook into this segue and customize it. Passing data between view controllers happens during a segue. In the example project, you can see the segue from MainViewController to TertiaryViewController.

Passing Data Between View Controllers in Swift, Passing data from one view controller to another view controller is something For coming back from VC2 to VC1, we use the “pop” method. This method removes the top view controller from the stack and makes the new top of the stack the active view controller. If the view controller at the top of the stack is the root view controller, this method does nothing. In other words, you cannot pop the last item on the stack. In addition to displaying the view associated with the new view

Comments
  • Are you sure sure all the ViewControllers are pushed to the NavigationController?