UIPopoverPresentationControllerDelegate方法仅在用户解雇时调用

Gre*_*tic 6 uipopovercontroller ios8

弹出窗口最大的问题之一是如何在用户解除弹出窗口时调用委托的解除方法(-[popoverPresentationControllerShouldDismissPopover:],-[popoverPresentationControllerDidDismissPopover:]),而不是以编程方式解除弹出窗口.

我的解雇方法中有很多重要的代码需要被调用.是否有一个优雅的解决方案,以确保即使在程序解雇时也会调用此代码?(当然,每当我解雇时,我都可以称之为"应该"和"做"......但这很容易出错,而且有点粗暴.)

谢谢.

Jor*_*n H 2

我不知道有什么比每次以编程方式关闭它时手动调用它更好的解决方案。

[self popoverPresentationControllerDidDismissPopover:self.popoverPresentation];
Run Code Online (Sandbox Code Playgroud)

这在 iOS SDK 中很常见。例如,如果您以编程方式在表视图中选择一行,则tableView:didSelectRowAtIndexPath:不会调用委托方法。