从另一个控制导航控制器

时间:2017-08-27 02:12:46

标签: ios swift uinavigationcontroller

我的视图控制器位于视图容器内。

我正在尝试使用紫色区域中的按钮更改绿色区域中的导航控制器。

在我的主视图控制器中,我有:

class MainViewController: UIViewController,Purpleprotocol,Greenprotocol {
    weak var infoNav : UINavigationController?
    weak var greenVC: GreenVC?
    weak var purpleVC: PurpleVC?
    weak var peachVC: PeachVC?

func changenav(whichbutton: String) {
        print ("changenav")
        print(whichbutton + "whichbuttonstring")

        if(whichbutton == "1"){
            print("change one")
            let svc = storyboard?.instantiateViewController(withIdentifier: "rootController") as! GreenVC
             self.infoNav?.pushViewController(svc, animated: true)
        }

        if(whichbutton == "2"){
            print("change two")
            let svc = storyboard?.instantiateViewController(withIdentifier: "secondController") as! SecondViewController
            self.infoNav?.pushViewController(svc, animated: true)
        }
    }

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "contentSegue" {
            print("contentSegue")
            let infoNav = segue.destination as! UINavigationController
            let greenVC = infoNav.viewControllers[0] as! GreenVC
            greenVC.delegate = self
        }

        if segue.identifier == "menuSegue" {
            let dvmenu = segue.destination as! PurpleVC
            purpleVC = dvmenu
            dvmenu.delegate = self
        }
    }

这个功能确实有效,我可以看到正在调用的“更改一个”等但导航控制器只是没有改变。不知道如何到达它我想是正确的。

Layout I'm working with

0 个答案:

没有答案