Getting the top most UIViewController
41,531
Solution 1
You want visibleViewController
:
The currently visible view can belong either to the view controller at the top of the navigation stack or to a view controller that was presented modally.
Solution 2
NSArray *viewContrlls=[[self navigationController] viewControllers];
[viewContrlls lastObject];
Author by
Senseful
Updated on December 14, 2020Comments
-
Senseful over 3 years
If I push view controllers and/or present modal view controllers on a
UINavigationController
, how can I find out what is the top mostUIViewController
? Or in my case, I want to know if a certainUITableViewController
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 theUINavigationController
(as opposed to those that were presented modally).