问题描述
我不使用情节提要创建应用程序,并且在我的应用程序的这一部分中,我只需要以编程方式创建从ThirdViewController
到FirstViewController
的展开序列.我知道如何使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!