0

I have VC1 which is a basic view controller, I then want to present VC2 which is inside a navigation controller. Whenever I present it, it doesn't display the navigation controller. I want this all done pragmatically. The code I have been using to present VC2 is:

func matchesPressed(sender: UIButton!) { let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches self.presentViewController(matchesTVC, animated: true, completion: nil) } 

How do I present the navigation controller it is inside as well?

2 Answers 2

3

Is the navigation controller in the storyboard? If so, give it a storyboard ID and replace your matchesTVC stuff with the navigation controller.

If matches is a standalone view controller in the storyboard, you can do it in code like this:

let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches let navContr = UINavigationController(rootViewController:matchesTVC) self.presentViewController(navContr, animated: true, completion: nil) 
Sign up to request clarification or add additional context in comments.

Comments

0

Instantiate the navigation controller that contains your view controller and present the navigation controller.

2 Comments

Thanks, but how do I do that?
Give your navigation controller an identifier and use the same code you already have, but with the new identifier.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.