我想在呈现模态的视图控制器中检测到模态解雇。
这种方法对于在新的卡模式上检测到新的iOS 13滑动解雇效果非常好:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "MyIdentifier" { segue.destination.presentationController?.delegate = self } } extension MyController: UIAdaptivePresentationControllerDelegate { func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { //clean up UI (de-selecting stuff) once modal has been dismissed } }
但是,如果模态通过动作以编程方式自行退出,则不会调用presentationControllerDidDismiss:
@IBAction func btnDismissTap(_ sender: Any) { self.dismiss(animated: true, completion: nil) }
这是一个错误,还是有一种方法可以通过编程方式调用任何“滑动”关闭,以便我可以相同的方式检测所有关闭?目前,我正在为我的模态编写额外的“解雇”委托方法,以解决此问题,这似乎是不必要的。
但是,如果模态通过动作以编程方式自行退出,则不会调用presentationControllerDidDismiss
self.dismiss(animated: true, completion: nil)
不需要调用它,因为您可以在代码中自行关闭模式。您可能不知道该模态已被解雇。您不需要接收解雇信号,因为您首先发出了解雇信号。
通常,您不会收到委托方法调用来报告您自己的代码所做的事情。委托方法报告用户操作。如果您自己在代码中所做的一切都作为委托方法调用返回,那将是疯狂的。