Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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 Swift在显示新的Viewcontroller后关闭当前Viewcontroller_Ios_Swift - Fatal编程技术网

Ios Swift在显示新的Viewcontroller后关闭当前Viewcontroller

Ios Swift在显示新的Viewcontroller后关闭当前Viewcontroller,ios,swift,Ios,Swift,在我的场景中,我正在尝试创建多个显示ViewController。在这里,在我需要关闭以前的ViewController之后,显示新的ViewController ViewController A(RootViewController)next按钮单击显示ViewController B然后查看控制器B next按钮单击显示ViewController C。现在,如果我关闭ViewController C,需要显示ViewController A 以下是您可以继续操作的方法 class VCA:

在我的场景中,我正在尝试创建多个
显示ViewController
。在这里,在我需要关闭以前的ViewController之后,显示新的ViewController

ViewController A(RootViewController)
next按钮单击显示
ViewController B
然后查看控制器B next按钮单击显示
ViewController C
。现在,如果我关闭ViewController C,需要显示
ViewController A


以下是您可以继续操作的方法

class VCA: UIViewController {
    @IBAction func onTapNextButton(_ sender: UIButton) {
        if let controller = self.storyboard?.instantiateViewController(withIdentifier: "VCB") as? VCB {
            self.present(controller, animated: true, completion: nil)
        }
    }
}
由于
VCC
嵌入在
UINavigationController
中,因此需要呈现
UINavigationController
而不是
VCC

对于此子类
UINavigationController
,将其设置为
情节提要中
UINavigationController
class

class VCB: UIViewController {
    @IBAction func onTapNextButton(_ sender: UIButton) {
        if let controller = self.storyboard?.instantiateViewController(withIdentifier: "NavVC") {
            self.dismiss(animated: false, completion: nil)
            self.presentingViewController?.present(controller, animated: true, completion: nil)
        }
    }
}

class NavVC: UINavigationController {}

class VCC: UIViewController {
    @IBAction func onTapCloseButton(_ sender: UIButton) {
        self.navigationController?.dismiss(animated: true, completion: nil)
    }
}

我建议你看一看@Craz1k0ek。没有什么明确的想法。我正在寻找当前的模型视图控制器。我不理解你的问题。当您取消C时,是否要显示A?或者你想在展示下一个VC之前关闭当前VC?@TejaNandamuri当我关闭C时,我需要显示A。最好使用导航控制器,并从中推送和弹出视图控制器,不是直接显示和取消。我在VC-C中有导航控制器。如何添加它?你的意思是VC-C是navigationController的rootViewController?是的,我嵌入了导航控制器。更新了答案。