Forum Xamarin.iOS

xamarin.ios Change the UINavigationController

bitsnbytesbitsnbytes Member ✭✭


I have multiple storyboards to help breakup a large App. Some have their own UINavigationController to help with Appearance Proxy usage and target specific "things" that only belong in a given UINavigationController (bar).

So the initial storyboard is loaded after the launch screen with the source less segue on the UINavigationController.

Then I was using .PresentViewController which works fine, if I wanted it to be laying over the previous page (its a modal).

However, .PushViewController does not respect the associated UINavigationController attached to it.

How can switch to a new UINavigationController and kill the old one along with the views on the stack after loading the new UINavigationController (which would have a root view associated with it.)

In otherwords, How can navigate to a new UINavigationController or change the existing UINavigationController to then push its associated view?

Any help would be appreciated, this one has me stuck.


  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    If you want to remove a specific ViewController in navigation stack . you could check the following code .

            var controllers = this.NavigationController.ViewControllers;
            var newcontrollers = new UIViewController[controllers.Length - 1];
            int index = 0;
            foreach (var item in controllers)
                if (!(item.GetType() == typeof(xxxViewController))) // xxxViewController is the  ViewController that you want to remove
                    newcontrollers[index] = item;
            this.NavigationController.ViewControllers = newcontrollers;
  • bitsnbytesbitsnbytes Member ✭✭

    Hey, thanks for the reply. Not quite what I'm after. I want to literally change the entire NavigationController. So NavigationControllerA is currently active with the stack of views. Now I want NavigationControllerB to take over and in doing so NavigationControllerA should cease to exist and then NavigationControllerB's root view controller loads. Is this even possible and/or out of line with best practices? Thanks again!

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai
     this.NavigationController.ViewControllers = newcontrollers;

    The above line is to set a new Navigation Stack. You could add any ViewController in it as you want .

Sign In or Register to comment.