2

I integrated a slide - out side bar menu like in Venmo or in groupme or facebook. and im trying to build the functionality to change the root view controller, or the main view to a new view controller based on the selected cell from the side bar menu.

i was told to look in my viewdidload method which has this code.

how do i add in a new view controller here? that swaps out for the "centerViewController"

override func viewDidLoad() { super.viewDidLoad()

centerViewController = UIStoryboard.centerViewController()
centerViewController.delegate = self

// wrap the centerViewController in a navigation controller, so we can push views to it
// and display bar button items in the navigation bar
centerNavigationController = UINavigationController(rootViewController: centerViewController)
view.addSubview(centerNavigationController.view)
addChildViewController(centerNavigationController)

centerNavigationController.didMoveToParentViewController(self)

let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
centerNavigationController.view.addGestureRecognizer(panGestureRecognizer)

}

2
  • Your question is not clear. What's wrong with the code you posted? Do you want to swap out the navigation controller's root view controller (as opposed to pushing another controller on its stack)? What is that first line, centerViewController = UIStoryboard.centerViewController(), supposed to be doing?
    – rdelmar
    Dec 17, 2014 at 0:50
  • I suggest, instead of replacing the root view controller, you can push the root view controller along with the side bar and present a new child view controller with a back button on the top left side. This way you will always have a way to go back to your root view and access the side bar. Dec 17, 2014 at 8:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.