1

I have a view controller (inside a navigation controller) that have a segmented control with 2 options and a container view where 2 UITableViewControllers will be shown according to the segment selected.

The first view is loaded in the storyboard by (crt + click) embed and linked to container, and the table loads ok, the table starts above the nav bar, but when I change the segment and the other view is loaded it starts at the top of the view, behind nav bar. (When I return to the first view too)

To change the view I follow this: Swift - How to link two view controllers into one container view and switch between them using segmented control?

And here is my code:

let viewControllerIdentifiers = ["categoriasTVC", "unidadesTVC"]

@IBAction func opcion(sender: AnyObject) {
    let newController = (storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentifiers[sender.selectedSegmentIndex]))! as UIViewController
    let oldController = childViewControllers.last! as UIViewController

    oldController.willMoveToParentViewController(nil)
    addChildViewController(newController)
    newController.view.frame = oldController.view.frame

    transitionFromViewController(oldController, toViewController: newController, duration: 0, options: .TransitionNone, animations:{ () -> Void in
        // nothing needed here
        }, completion: { (finished) -> Void in
            oldController.removeFromParentViewController()
            newController.didMoveToParentViewController(self)
    })

}

How can I keep the navigation controller inset?

Community
  • 1
  • 1

0 Answers0