Mischa
Mischa

Reputation: 17269

Get a reference to the currently visible view controller

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.

Upvotes: 4

Views: 4565

Answers (1)

chris13
chris13

Reputation: 640

UINavigationController has a property called topViewController. Maybe it helps you.

Upvotes: 5

Related Questions