I am trying to get the current UIViewController display, which is missing in AppDelegate, but it always gets the initial top UIViewController , not the current one.
The following code in AppDelegate MUST get the current UIViewController , but this same function does not work when I use it in any of my View controllers:
func getTopViewController() -> UIViewController { var topViewController = UIApplication.sharedApplication().delegate!.window!!.rootViewController! while (topViewController.presentedViewController != nil) { topViewController = topViewController.presentedViewController! } return topViewController }
The above code was provided as an answer on a similar question: Get the current display of the UIViewController on the screen in AppDelegate.m
No matter how deep I go, I can only get the first view of the View Controller.
How can I get the current presentation of the UIViewController ?
FYI: I am NOT using the UINavigationController , only the regular UIViewController classes.
source share