【发布时间】:2017-06-24 09:53:53
【问题描述】:
我有两个 swift UI 视图控制器:
class AViewController:UIViewController {
[...]
func OnBluetoothEventA() {
performSegue(withIdentifier: "BSegue", sender: self)
}
func OnBluetoothEventB() {
// Go back to this viewcontroller!
}
}
class BViewController:UIViewController {
[...]
}
当用户关闭蓝牙时,我执行 segue 以显示动画和消息。
当用户打开蓝牙时,我想恢复以前的 ViewControl。
哪种方法最快捷?
【问题讨论】:
-
您可以为此目的使用 KVO(键值观察器)。在蓝牙关闭时添加观察者,然后触发 firstViewController 中的方法转到 secondViewController。再次在 secondViewController 中使用另一个观察者来观察蓝牙何时打开。现在google一下如何在swift中使用KVO。
标签: ios swift segue unwind-segue