I have a UIAlertView. When the user taps a button in the alert view I want to show a new UIViewController.
In order to achieve this I need to know which view controller is currently visible on screen because that particular view controller is the right one to present the new view controller.
The problem is that I have a complex hierarchy of view controllers in my app including a UINavigationController and a UITabBarController (among others). So I cannot simply use self.visibleViewController to get the currently visible view controller.
I have found a possible solution on Stackoverflow but I would like to find a neater solution without having to dig through the whole view controller stack.
UIAlertViewis not necessarily aUIViewController. It can be any class that conforms to theUIAlertViewDelegateprotocol. In my case the delegate is actually aUIViewControllerbut it is a specific one that is not always visible.UIAlertViewis not necessarily presented by a specificUIViewController. Instead, I use[alertView show]. I can call that method from anywhere in my code because a UIAlertView always creates its own window.