If I push view controllers and/or present modal view controllers on a UINavigationController
, how can I find out what is the top most UIViewController
? Or in my case, I want to know if a certain UITableViewController
is the top most or not.
I tried using:
self.navigationController.topViewController == self
... but this doesn't work. I'm guessing that it's failing because I'm presenting modal view controllers on top of it and that the topViewController
only keeps track of which views were pushed on the UINavigationController
(as opposed to those that were presented modally).
You want
visibleViewController
:I know the question is old, but it's still popular - that's why I'd like to post my best solution which handles different
UIViewController's
subclasses. At the same time you can extend functionality of this method by your custom "collection" controllers such as side menu.