Swift:展开期间的 performSegueWithIdentifier 不起作用

Swift: performSegueWithIdentifier during unwind not working

我创建了一个典型的展开流程,从我的视图控制器 #2 返回到视图控制器 #1,使用以编程方式创建的按钮,使用 segue to Exit 技术。

我有跟踪语句确认按钮代码正在完美执行,并且正在使用正确的 segue ID 调用 #2 performSegueWithIdentifier 函数,但没有任何反应。

澄清一下:

我已将视图控制器 #2 连接到出口并确认 segue ID 在所有地方都是准确的。我在 #2 performSegueWithIdentifier 函数中追踪了 #2 标识符,它完全匹配。

据我了解,我不再需要使用 dispatch 修复当前版本的 2016 XCode。无论如何我都试过了,但没有任何效果。没有崩溃,只是没有放松。

不知何故,放松技术并没有使用这种退出技术来逆转。有什么想法吗?

我一直在关注这里的教程:https://spin.atomicobject.com/2014/12/01/program-ios-unwind-segue/

代码VC#2:

// action func wired to button, fires perfectly
func unwind(seg:UIStoryboardSegue!) {

    self.performSegueWithIdentifier("unwind", sender: self)
}

在 VC1 中你需要一个函数:

@IBAction func unwindToVC1(segue:UIStoryboardSegue) {
}

然后在故事板中按住 ctrl 从黄色视图控制器图标拖动到退出图标,然后从弹出窗口 select unwindToVC1:

给unwind segue一个标识符,比如说unwindToVC1

现在,在 VC2 中,创建您的按钮 touchUpInside 处理程序:

func buttonTapped(sender:UIButton) {
    self.performSegueWithIdentifier("unwindToVC1")
}

当您以编程方式设置按钮时,将此方法添加为操作处理程序:

button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)
  1. unwind 函数移动到 VC1。将该实现留空,或者放置一个打印语句以查看它是否进入该函数。
  2. 确保在情节提要中有一个使用标识符 "unwind"
  3. 创建的展开转场
  4. 添加一个在 VC2 中调用 performSegueWithIdentifier("unwind"...) 的按钮动作函数 buttonAction:(button:UIButton)
  5. buttonAction 设置为以编程方式创建的按钮的操作。