ios - 回到 UIViewController 不会触发 segue

标签 ios swift delegates segue

我有 Controller B,它使用委托(delegate)模式将数据发送回 Controller A,但由于某种原因我的 segue 没有触发。

是否有什么东西阻止我的 segue 被触发?我将如何解决这个问题?

Controller B - 模态呈现

@IBAction func addButton(_ sender: Any) {
        delegate?.select(sID: selectedID)
        dismiss(animated: true, completion: nil)
    }

Controller A

func select(sID: String) {
        performSegue(withIdentifier: "editSegue", sender: self);
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "editSegue" {
            if let destinationVC = segue.destination as? NewController {
                destinationVC.selectedQueryID = selectedQueryID;
                print(“test”);
            }
        }
        if segue.identifier == "selectSegue" {
            if let destinationVC = segue.destination as? ControllerB {
                destinationVC.queryID = selectedQueryID;
                destinationVC.delegate = self;
            }
        }
}

Controller C - 模态呈现(不呈现自身)

最佳答案

在B View Controller 中,dismiss完成时触发

@IBAction func addButton(_ sender: Any) {

    dismiss(animated: true, completion: {
         delegate?.select(sID: selectedID)
   }
}

还要确保您以模态方式呈现 B viewcontroller。

关于ios - 回到 UIViewController 不会触发 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53374390/

相关文章:

ios - 在 UIScrollView 上实现缩放

ios - 使用 CGColor

ios - 如何使用协议(protocol)/委托(delegate)在 UIViewController 之间传递数据

ios - 如何为图像和消息创建条件?

ios - 如何以编程方式为文本添加大纲?

ios - 自定义 UIView 添加目标?

objective-c - 为什么我的委托(delegate)不接受 performSelectorOnMainThread :withObject:waitUntilDone:?

c# - 无法将类型 'int' 隐式转换为 'Foo.Bar.Delegates.Program.ParseIntDelegate'

ios - 在设备上运行但不在 Swift 模拟器中运行时的断点

ios - 蓝牙停止主线程