如何在swift ios中解雇2个视图控制器? [英] How to dismiss 2 view controller in swift ios?

查看:180
本文介绍了如何在swift ios中解雇2个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Swift iOS中关闭2个视图控制器?

How to dismiss 2 view controllers in Swift iOS?

以下是我的代码。

@IBAction func backButtonTapped(sender: AnyObject) {
    self.presentingViewController
        .presentingViewController
        .dismissViewControllerAnimated(true, completion: nil)
}


推荐答案

有特殊的展开segue 目的,它旨在回滚到堆栈中的某个视图控制器。

There's special unwind segue for that purpose, it is intended to roll back to certain view controller in stack.

让我们将最顶层的控制器(你来自哪里)称为 source 并且堆栈中的控制器(您想要回滚到顶部)作为目的地

Let's call the topmost controller (where you go from) as source and the controller in stack (which you want to roll back to top) as destination.


  1. 目的地中创建 IBAction ,以便在展开时触发:

  1. create IBAction in destination to be triggered on unwind segue:

@IBAction func myUnwindAction(segue:UIStoryboardSegue){}

它可以是空白。


  1. source 控制器中通过从控制器图标拖动到退出一个来创建展开segue,它将找到您在步骤1中创建的操作。调用segue 展开

  1. in source controller create an unwind segue by dragging from the controller icon to exit one, it will find the action you created at the step 1. Call the segue unwind.

现在你可以用常规代码发出那个segue

now you can issue that segue from code with regular

performSegueWithIdentifier(unwind,sender:nil)

I描述了如何从代码中发出unwind segue。对于按钮展开,可以通过拖动按钮直接在IB中创建segue来退出图标。

I described how to issue unwind segue from code. For buttons unwind segues can be created in IB directly by dragging a button to exit icon.

还要查看此讨论以获取更多信息:如何以编程方式执行Unwind segue?

Also check this discussion for more info: How to perform Unwind segue programmatically?

这篇关于如何在swift ios中解雇2个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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