如何关闭 VIewController iOS Swift [英] How to dismiss VIewController iOS Swift

查看:27
本文介绍了如何关闭 VIewController iOS Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发的新手.我正在使用 iOS Swift 开发应用程序.我有 3 个视图控制器 viewController1、viewController2、viewController3.当我从 viewController1 单击它移动到 viewController2.通过使用以下代码

I am new to iOS development. I am developing an application using iOS Swift. I have 3 view controllers viewController1, viewController2, viewController3. When I click from viewController1 its move to viewController2. By using the following code

let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let secondViewController = storyboard.instantiateViewControllerWithIdentifier("viewController2")
        presentViewController(secondViewController, animated: false, completion: nil)

现在我使用以下代码从 viewController2 移动到 viewController3

Now I am moving from viewController2 to viewController3 by using the following code

performSegueWithIdentifier("viewController3", sender: scoreColorArray);

一切都好.现在我想从 viewController3 返回到 viewController1.我的问题不是去viewController1,而是去viewController2.我知道 viewController2 没有被解雇的原因.

It's all fine. Now I want to back from viewController3 to viewController1. My problem it is not going to viewController1 it is going to viewController2. I know the reason viewController2 not dismissed.

我想关闭当前的视图控制器并开始新的.我该怎么做?我知道有一些方法可以做到这一点,请有人帮我找到问题.

I want to dismiss the current view controller and start new one. How can I do it? I know there is some ways to do it, please someone help me to finds the issue.

推荐答案

因为你的演示顺序是 VC1 -> VC2 -> VC3您需要在 VC3 上调用 self.presentingViewController?.presentingViewController?.dismissViewControllerA‌ animated,以这种方式反向遍历您的序列.

Since your presentation sequence is VC1 -> VC2 -> VC3 you need to call self.presentingViewController?.presentingViewController?.dismissViewControllerA‌​animated on VC3, traversing this way your sequence in reverse.

这篇关于如何关闭 VIewController iOS Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆