Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentedViewController Changes KVO

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?

like image 271
user2916412 Avatar asked Oct 24 '13 15:10

user2916412


1 Answers

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) {
...
}
like image 164
khaullen Avatar answered Sep 23 '22 07:09

khaullen