如何以编程方式创建Unwind segue [英] How to create Unwind segue programmatically

查看:122
本文介绍了如何以编程方式创建Unwind segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不使用情节提要创建应用程序,并且在我的应用程序的这一部分中,我只需要以编程方式创建从ThirdViewControllerFirstViewController的展开序列.我知道如何使用sotorybard进行此操作,但找不到如何以编程方式进行操作的任何解决方案.有任何建议吗?

I make an application using no storyboard and in this part of my app I need to create a unwind segue from ThirdViewController to FirstViewController programmatically only. I know how to do it using sotorybard but can't find any solution how to do it programmatically. Any sugestions?

推荐答案

如果没有情节提要,您将无法创建实际的 segue ,但是您可以通过在navigationController.这是连接到按钮以从ThirdViewController返回到FirstViewController的示例:

You can't create an actual segue without a Storyboard, but you can do the equivalent action by calling popToViewController on navigationController. Here is an example that is connected to a button to return to FirstViewController from ThirdViewController:

@IBAction func goBackToFirstVC(sender: UIButton) {
    guard let controllers = navigationController?.viewControllers else { return }
    let count = controllers.count
    if count > 2 {
        // Third from the last is the viewController we want
        if let firstVC = controllers[count - 3] as? FirstViewController {
            // pass back some data
            firstVC.someProperty = someData
            firstVC.someOtherProperty = moreData

            navigationController?.popToViewController(firstVC, animated: true)
        }
    }
}

viewWillAppear的替代中,您可以对传回的数据进行处理.

In an override of viewWillAppear, you can act upon that data that was passed back.

这篇关于如何以编程方式创建Unwind segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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