0

Is there a trick to push to child view controllers from a parent vc that previously has been presented modally?

Method to present parent that I'm using:

    let parentVC = ParentController()
    self.present(parentVC, animated: true, completion: nil)

Method to then push to child controllers which doesn't work:

    let childVC = childController()
    navigationController?.pushViewController(childVC, animated: true)
rantanplan
  • 243
  • 3
  • 17

1 Answers1

1

Is there a trick to push to child view controllers from a parent vc that previously has been presented modally?

If you present a vc modally and you want this vc to push a child vc, you have to present the vc embedded in a UINavigationController.

    let parentVC = ParentController()
    self.present(parentVC, animated: true, completion: nil)

to become

    let parentVC = ParentController()
    let parentNav = UINavigationController(rootViewController: parentVC)
    self.present(parentNav, animated: true, completion: nil)

then you can do, in parentVC:

    let childVC = childController()
    navigationController?.pushViewController(childVC, animated: true)
Calvin
  • 575
  • 1
  • 4
  • 9
  • Great, that's what I was looking for! Thanks! – rantanplan Jun 07 '18 at 09:32
  • Following up on this - I noticed that the animation when pushing from the modal view is different than from push to push. It appears to be sliding in from the top right corner (instead of the entire view sliding in horizontally). Is there a way to turn that off / switch to the default horizontal slide? Note here, I have the navigation bar set to hidden and am using a custom nav bar in case that is important for this. – rantanplan Jun 08 '18 at 15:32
  • I am not sure if I can visualize your problem right here because the `pushViewController` is default horizontally sliding. You may open a new question to provide more details of your code. – Calvin Jun 08 '18 at 16:05