Is there a way to know the current viewController in the memory. I am in a NSObject subclass which is being called from multiple view controllers. I do not want to add an extra parameter and pass it to my NSObject subclass. Is there any UIApplication method which I can call in my NSObject class to get the latest view controller in the memory.
Share
No, because you’re misunderstanding how view controllers work. View controllers control a view. That’s it. While a view may usually take up the entire screen, it doesn’t have to. For example, an iPad app with a split view controller and a visible UIPopoverController actually has (at least) 4 visible views all controlled by different view controllers. There’s the
UISplitViewControllerand it’s main content area, there’s theUIViewControllercontrolling the left (“master”) area of the split view controller, anotherUIViewControllercontroller the right (“detail”) area of the split view controller, and a fourth view controller for controlling the contents of the popover.Which one of those would you say is the “latest view controller”?
And the correct answer would be: none.