thejuki thejuki - 4 months ago 70x
iOS Question

Replace current navigation controller with another navigation controller

I've tried to use:

self.navigationController?.setViewControllers([anotherNavController], animated: true)

However, I get a
. I'm assuming you cannot have a
within another one because using
with a normal view controller works fine.

All I need is to dismiss the current navigationController and present another navigationController so that when the new navigationController is dismissed, in the future the old navigationController is not re-present.

I am using [PageMenu][1] which complicates things.

Example of why I need to replace the whole navigation controller:

enter image description here

This code initializes the PageMenu in ViewDidAppear:

// Initialize scroll menu
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)



EDIT: (RESOLVED) I was able to get this working after playing around with CGRectMake and setViewControllers.



If you're setting up your PageMenu without StoryBoard, you'll need to instantiate the rootViewController in your AppDelegate. This should get rid of the need to switch from the default navigationController to your own.

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    self.window?.rootViewController = YourViewController(nibName: "YourViewController", bundle: nil)


    return true

For additional help setting up a PageMenu without StoryBoard, check out the demo code here.