简体   繁体   English

Swift 4 Unwind Segue无法在导航控制器上运行

[英]Swift 4 Unwind segue not working on navigation controller

I am working on an app in Swift 4 and I am trying to unwind a segue. 我正在使用Swift 4开发一个应用程序,并且正在尝试取消序列。 I have a Table View Controller, When the user selects a cell, the segue happens to a navigation controller which has a relationship root view controller with another controller I have UIViewController . 我有一个表视图控制器,当用户选择一个单元格时,选择发生在导航控制器上,该控制器具有根视图控制器与另一个具有UIViewController控制器的关系。 In the UIViewController I have a UIButton inside Navigation Items, I have unwind set with the UIButton by selecting the button and dragging to exit and I have the unwind code inside the UITableViewController like so: UIViewController我在Navigation Items中有一个UIButton ,通过选择按钮并拖动以退出以设置UIButton的展开,并且在UITableViewController具有展开代码,如下所示:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            if segue.identifier == "segueRSVP" {
            }
        }



    @IBAction override func unwind(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
        print("Here")
    }

But nothing happens, it doesn't even get triggered. 但是什么也没发生,甚至都不会触发。

Here are my screenshots: 这是我的截图:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Add this unwind to your RSVP controller: 将此展开添加到您的RSVP控制器中:

@IBAction func unwindToThisViewController(segue: UIStoryboardSegue) {
    print("IM BACK")
}

Then control + drag the button in your detail controller up to the exit and select the method: unwindToThisViewController 然后控制+拖动细节控制器中的按钮直至退出并选择方法:unwindToThisViewController

Just tested this on xcode swift 4 and it should work 刚刚在xcode swift 4上进行了测试,它应该可以工作

I'm not sure why, but when I "overrode" unwind, it didn't work for me either, so I set up my own ibaction 我不确定为什么,但是当我“改头​​换面”放松时,它对我也不起作用,因此我设置了自己的练习

In my case, was tagging the swift unwind func with @objc keyword. 就我而言,是用@objc关键字标记了快速展开功能。

@objc func unwindToThisViewController(segue: UIStoryboardSegue) { ... }

Hope this works. 希望这行得通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM