How to present a view controller inside a navigati

2019-08-29 18:59发布

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条回答
可以哭但决不认输i
2楼-- · 2019-08-29 19:09

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)
查看更多
Summer. ? 凉城
3楼-- · 2019-08-29 19:25

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

查看更多
登录 后发表回答