Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 导航到ViewController并单击_Ios_Swift_Cocoa Touch_Uiviewcontroller_Uinavigationcontroller - Fatal编程技术网

Ios 导航到ViewController并单击

Ios 导航到ViewController并单击,ios,swift,cocoa-touch,uiviewcontroller,uinavigationcontroller,Ios,Swift,Cocoa Touch,Uiviewcontroller,Uinavigationcontroller,在这里,我解雇了一位VC,并试图在新VC中导航,但导航不起作用。解雇VC工作正常 @IBAction func onClickEmailBtn(_ sender: UIButton) { //dismiss VC self.dismiss(animated: false, completion: nil) //Navigate to VC DispatchQueue.main.async { let cevc = self.storyboard?.

在这里,我解雇了一位VC,并试图在新VC中导航,但导航不起作用。解雇VC工作正常

@IBAction func onClickEmailBtn(_ sender: UIButton) {
    //dismiss VC
    self.dismiss(animated: false, completion: nil)
    //Navigate to VC
    DispatchQueue.main.async {
        let cevc = self.storyboard?.instantiateViewController(withIdentifier: "CEVC") as! EmailViewController
        self.navigationController?.pushViewController(cevc, animated: true)
    }
}

在这里,我有一个名为VC1的NavigationViewController,在此基础上,我将介绍一个名为VC2的VC。在这个VC2中,当我单击按钮时,我想浏览名为EmailVC的新VC。

尝试使用下面的代码查找导航控制器,并用控制器名称替换Viewcontroller

let productVC = SeconViewViewController()
let parentVC = (parent!.presentingViewController as! ViewController).childViewControllers.first as! UINavigationController
self.navigationController?.dismiss(animated: true, completion: {
     parentVC.pushViewController(productVC, animated: true)
})

尝试使用以下代码查找导航控制器,并用控制器名称替换Viewcontroller

let productVC = SeconViewViewController()
let parentVC = (parent!.presentingViewController as! ViewController).childViewControllers.first as! UINavigationController
self.navigationController?.dismiss(animated: true, completion: {
     parentVC.pushViewController(productVC, animated: true)
})
试试这个代码

@IBAction func onClickEmailBtn(_ sender: UIButton) {

    if let controller = self.storyboard?.instantiateViewController(withIdentifier: "CEVC") as! EmailViewController {
         self.dismiss(animated: false, completion: nil)
         self.presentingViewController?.present(controller, animated: true, completion: nil)
    }
}
试试这个代码

@IBAction func onClickEmailBtn(_ sender: UIButton) {

    if let controller = self.storyboard?.instantiateViewController(withIdentifier: "CEVC") as! EmailViewController {
         self.dismiss(animated: false, completion: nil)
         self.presentingViewController?.present(controller, animated: true, completion: nil)
    }
}

您试图阻止ViewVoController关闭view controller, 您已经接受的答案是,从解除viewController开始,呈现viewController。虽然这可能符合你们的目的,但我将回答你们最初的问题

   // get the object of presenting nanvigation controller(navigation controller with has presented this view controller)
    let presentingNavigationController = presentingViewController?.navigationController
    dismiss(animated: true) {
        let cevc = self.storyboard?.instantiateViewController(withIdentifier: "CEVC") as! EmailViewController
        // here you push your view controller with presentingNavigationController
        presentingNavigationController?.pushViewController(cevc, animated: true)
    }

您试图阻止ViewVoController关闭view controller, 您已经接受的答案是,从解除viewController开始,呈现viewController。虽然这可能符合你们的目的,但我将回答你们最初的问题

   // get the object of presenting nanvigation controller(navigation controller with has presented this view controller)
    let presentingNavigationController = presentingViewController?.navigationController
    dismiss(animated: true) {
        let cevc = self.storyboard?.instantiateViewController(withIdentifier: "CEVC") as! EmailViewController
        // here you push your view controller with presentingNavigationController
        presentingNavigationController?.pushViewController(cevc, animated: true)
    }

您能否也共享层次结构,是否显示了当前控制器?找到根导航控制器并尝试使用该控制器进行推送。@SGDev,我有一个名为VC1的VC,我正在显示另一个名为VC2的VC,当我在该VC2中单击btn时,我想导航新的VC3。在这里,我用`let vc=UIStoryboard(名称:“Main”,bundle:nil)向VC2演示!SecondViewController//present modal self.present(vc,动画:false,完成:nil)`尝试在self.dismise的完成处理程序中添加pushViewController代码,没有主队列@manishharma93,你能帮我写代码吗…你能不能也共享层次结构,是否显示了当前控制器?找到根导航控制器并尝试使用该控制器进行推送。@SGDev,我有一个名为VC1的VC,我正在显示另一个名为VC2的VC,当我在该VC2中单击btn时,我想导航新的VC3。在这里,我用`let vc=UIStoryboard(名称:“Main”,bundle:nil)向VC2演示!SecondViewController//present modal self.present(vc,动画:false,完成:nil)`尝试在self.dismise的完成处理程序中添加pushViewController代码,而不使用主队列@manishharma93,你能帮我写代码吗?它有错误模式匹配条件需要'case'关键字insert case and what is controller以后会忽略self,self在层次结构中不存在,但是self.presentingViewController存在。通过使用presentingViewController,我可以推送我的EmailViewController。@SGDev您可以在关闭视图控制器时提供视图控制器,但不能在执行时推送。OP的问题是如何阻止viewController解除viewController您也可以使用presentingViewController进行推送。在需要“case”关键字插入case和什么是控制器的情况下,会出现错误模式匹配会解除自身,层次结构中不存在self,但self.presentingViewController存在。通过使用presentingViewController,我可以推送我的EmailViewController。@SGDev您可以在关闭视图控制器时提供视图控制器,但不能在执行时推送。OP的问题是如何阻止viewController关闭viewController您也可以使用presentingViewController进行推送。