所以通常我会为此使用委托(delegate)模式,但这是一个棘手的情况。
View Controller A 呈现 -> View Controller B 呈现 -> View Controller C。
当用户完成 View Controller C 中的步骤时,我将在一次调用中关闭 B 和 C
self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
我想将数据从 View Controller C 传递回 A。这怎么可能,因为 A 没有引用 C,我如何实现委托(delegate)?
****编辑:这一切都是以编程方式完成的,所以我不能使用 unwind segues
***** 解决方案 *******
我找到的最佳解决方案是在 VC A 中添加一个观察者,并在关闭 VC 时将对象发布到 VC C 中:
self.presentingViewController?.presentingViewController?.dismiss(animated: true) {
NotificationCenter.default.post(name: Notification.Name("UpdateKeywords"), object: self.account)
}
不要忘记在 deinit() 中移除 VC A 中的观察者
最佳答案
我通常会做的是在 b 中创建对 A 的引用,然后在 C 中创建对该引用的引用,然后,就在您传回 A 之前,对引用进行更改,然后调用 self。 presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
关于ios - 如何将数据从模态视图 Controller 传回 View 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40363377/