Is there anyway to determine if a modal view controller is currently being shown? currently on view?
I have an issue where a viewDidAppear is being called twice and only needs to be called once, to resolve I would like to see if a modal view controller is on the screen if it is run one bit of code, else nothing.
It would be useful if I could code inside the current view controller on the navigation stack, and see if a modal view controller is on top of that at the present time?
The correct place to check on the wellbeing of a modal viewController, is in it’s presenting viewController. The presenting viewController ought to know whether its presented viewController is still present, or has been dismissed (it is responsible for both tasks). The presentingViewController has a property,
presentedViewControllerwhich carries the reference you need.If the modal VC has been covered up, for example by itself pushing another viewController, you would be able to ascertain that from it’s navController.viewControllers array property: again, the best reference source goes back to the presenting viewController.
If you can’t get a reference to the modal viewController from it’s presenting viewController, there is probably is something wrong with your design, you need to rethink.