Push UINavigationController programmatically. iOS9

2019-05-31 05:57发布

I want to display a navigation controller programmatically. This code works perfect on iOS 8, but on iOS 9 it doesn't work.

var vc = storyboard?.instantiateViewControllerWithIdentifier("view_controller_id") as! UIViewController;
var nc = UINavigationController()
        nc.setViewControllers([vc], animated: false)
        navigationController?.pushViewController(nc, animated: true)

After that I am getting this error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

1条回答
ゆ 、 Hurt°
2楼-- · 2019-05-31 06:20

You can't push a navigation controller to another navigation controller. You will have to show your navigation view controller with viewcontrollers modally or just push your view controllers to the active navigation controller.

查看更多
登录 后发表回答