Find ViewController in NavigationController with special key

get current view controller in uinavigationcontroller
get current navigation controller swift
how to get previous view controller from navigation controller swift
uinavigationcontroller tutorial
check if viewcontroller is in navigation stack swift
get root view controller swift
get viewcontroller from navigation controller swift 3
swift get presenting view controller

I have a NavigationController with different ViewControllers. Sometimes I want to push a ViewController to NavigationController, which is already included. In this case I want to move to the existing from TopController, and pop all other ViewControllers between top and the existing one.

Is there a way to give a ViewController a special id (for example a NSString), to find him later in "NavigationController.viewControllers"? Or should I use a seperate Dictionary to manage my ViewControllers?

Or is there a better way, I dont consider.

best regards

On your appDelegate, you can store all your ViewController and when you want to pop call :

[self.navigationController popToViewController:yourViewController animated:YES];

Or you can try to search

NSArray *viewControllers = self.navigationController.viewControllers 
for (UIVIewController *anVC in viewControllers) {
    if (anVC isKindOfClass:[yourController class] {
        [self.navigationController popToViewController:anVC animated:YES];
        break;
    }
}

Hope it will help you.

Find ViewController in NavigationController with special key, Is there a way to give a ViewController a special id (for example a NSString), to find him later in "NavigationController.viewControllers"? Or should I use a� If the view controller or one of its ancestors is a child of a navigation controller, this property contains the owning navigation controller. This property is nil if the view controller is not embedded inside a navigation controller.

Note : As the view controllers are the same class, most times
Add strUniqueID property on each controller while pushing view controller to navigation controller don't forget to set it

Now you know which unique ID's you want remove, so find it

//Firstly find your viewController
for(id viewcontroller in self.navigationController.viewControllers)
{
     //For finding specific viewController use isKindOfClass
     if(viewcontroller isKindOfClass:[YourViewControllerNameHere Class])
     {
         //Now find UniqueIDHere
         YourViewController *objYourViewController = (YourViewController *)viewcontroller
         if(YourViewControllerNameHere.strUniqueID isEqualToString:removeUniqueIDHere])
         {
             //Now pop to YourViewController
             [self.navigationController popToViewController:viewcontroller animated:YES];
             break;
         }
         
     }
     else if(viewcontroller isKindOfClass:[YourDifferentViewControllerNameHere Class]) //Different ViewControllers here like this
     {
         //Now find UniqueIDHere
         YourDifferentViewController *objYourDifferentViewController = (YourViewController *)viewcontroller
         if(YourDifferentViewController.strUniqueID isEqualToString:removeUniqueIDHere])
         {
             //Now pop to YourViewController
             [self.navigationController popToViewController:viewcontroller animated:YES];
             break;
         }
     }
       
}

Try this :

//Firstly find your viewController
for(id viewcontroller in self.navigationController.viewControllers)
{
     //For finding specific viewController use isKindOfClass
     if(viewcontroller isKindOfClass:[YourViewControllerNameHere Class])
     {
         //Now pop to YourViewController
         [self.navigationController popToViewController:viewcontroller animated:YES];
         break;
     }
}

UINavigationController, The user can also remove the topmost view controller using the back button in the navigation bar or using a left-edge swipe gesture. The navigation controller� The navigation controller creates the views—such as the navigation bar and toolbar—that are used for the navigation interface, and it is responsible for managing those views. Figure 1-2 shows the relationship between the navigation controller and these key objects. Figure 1-2 Objects managed by the navigation controller

Swift 5

let vc = navVC.viewControllers.first(where: { $0.hasKey })

UINavigationBar, The primary components are a left (back) button, a center title, and an optional A navigation controller uses the navigationItem property on UIViewController to� The split view controller returns your original view controller through view Controller(for:), but its children property contains the navigation controller it used to wrap your view controller. After you assign view controllers to specific columns, you can show and hide those columns using show(_:) or hide(_:) .

Find the current top view controller for your iOS application � GitHub, UIViewController *lastViewController = [[navigationController viewControllers] lastObject];. return [self topViewController:lastViewController];. } UIViewController � After introducing how to implement Coordinator pattern with an MVVM structure, it feels natural for me to go further and cover some of the blank spots of Coordinator and how to fix along the way.

How to Get the Root View Controller of a Navigation Controller, Navigation controllers are indispensable on iOS, tvOS, and, more recently, Mac Catalyst. The UINavigationController class is easy to work with. A navigation controller, an instance of class UINavigationController, is essentially a container for multiple view controllers. They’re organized on a stack , using an ordered array. You can navigate horizontally between view controllers, using an approach known as pushing and popping .

Navigation Controllers, And you can also find navigation controller again, right here in the object. Since we already have our view controller, which is this nice, social, pink view So you can, like if we drag this, it has a special one called a relationship This is a very important part about navigation controller as that is where the back button goes. To connect the gesture recognizer to the ViewController.swift code. Control-drag from the gesture recognizer in the scene dock to the code display in the editor on the right, stopping the drag at the line below the //MARK: Actions comment in ViewController.swift. In the dialog that appears, for Connection, select Action.

Comments
  • Are some of the view controllers the same class, or are they all different?
  • Most times the same class, but different contents. But I have a unique ID for every content.
  • The view controllers are the same class, most times.
  • Ok, so add a custom property like a tag or id, and if(anVC.tag == lookingTag) it's the good one. Or use the first method with view controllers storage.
  • The view controllers are the same class, most times.