I'm trying to listen to changes for the presentedViewController, but it doesn't look like that property is KVO compliant (or at least I'm not able to get changes from it). Is there a way in UIViewController to listen to changes when a UIViewController is actively presented?
presentedViewController
doesn't appear to be KVO-compliant, but it is possible to be notified of changes by overriding the relevant presentation/dismissal methods of UIViewController
:
override func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?) {
// will present view controller
super.presentViewController(viewControllerToPresent, animated: flag, completion: completion)
}
override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
super.dismissViewControllerAnimated(flag, completion: completion)
// did dismiss view controller
}
Swift 4:
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With