I know I can use popoverPresentationControllerDidDismissPopover
but that is only called when the user taps outside the popover view to dismiss it.
When I dismiss the popover manually (self.dismissViewControllerAnimated(true, completion: nil)
in the popover's ViewController) nothing happens.
Detect popover dismiss
Popover Dismiss!
There are two ways of detecting popover dismiss:
- Detecting in
mainViewController
, where it was actually generated, I meanParentViewController
.
Using the parentViewController
as the main generating personal
class ViewController: UIViewController, UITableViewDataSource,
UITableViewDelegate, UIPopoverPresentationControllerDelegate {
And now implementing these functions:
public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
public func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
print("Popover dismisssed")
}
- Detecting in the controller used to handle
popOverView
made in storyboard.
func dismiss() {
self.dismiss(animated: true, completion: nil)
print("DISMISSS")
}
@IBAction func cancelClicked(_ sender: Any) {
dismiss()
}
NOTE: For storyboards you can ask further details.
Another point is to check if you have any class inherited from your class which also implement the same method of func popoverPresentationControllerDidDismissPopover(...)
. If so, make sure the upper level class call the base class method like this:
class MyINheritedClass: UIPopoverPresentationControllerDelegate {
...
override func popoverPresentationControllerDidDismissPopover(
_ popoverPresentationController: UIPopoverPresentationController)
{
super.popoverPresentationControllerDidDismissPopover(
popoverPresentationController) // Make this call
...
}
}
Otherwise, your base level class method will never be called!
© 2022 - 2024 — McMap. All rights reserved.
popoverPresentationControllerDidDismissPopover
and where you callself.dismissViewControllerAnimated(true, completion: nil)
. – Kremlin