Embed Container View with Navigation Controller Programmatically

人走茶凉 提交于 2019-12-10 23:36:08

问题


I want to embed a Navigation controller with the container view and use the same navigation controller to push some other view controller. Here is the workaround with the help of storyboard.

Can I embed the navigation controller with Container View programmatically? I can able to add SecondViewController's content as a subview in the container view. But in that case, my Navigation controller will not work.

In the BaseViewController I have added this code,

let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController")
let navigationController = CustomNavigation(rootViewController: secondViewController!)
// taking a navigation controller reference, so that I can use this to Push other view controller.
Helper.shared.customNavController = navigationController 
self.addChildViewController(navigationController)
secondViewController?.view.frame = CGRect(x: 0, y: 0, width: containerView.frame.size.width, height: containerView.frame.size.height)
containerView.addSubview((secondViewController?.view)!)

It added the SecondViewController's content in the Container View. But using this navigation controller (Helper.shared.customNavController) I am not able to Push any other View Controller.

来源:https://stackoverflow.com/questions/50363385/embed-container-view-with-navigation-controller-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!