I'm having this issue (error is reported by Flurry analytics from some users, but I cannot reproduce it neither on my device nor simulator):
NSInvalidArgumentException: Application tried to present modally an active controller <CityViewController: 0x361b20>.
Do you know anything about this error? Has it happened to you?
Application has three hierachically sorted views: master view controller with list of locations and detail view (the CityViewController mentioned in error message) is automatically presented when user is at one of known locations. Whenever location significantly changes, detail view is dismissed first before opening new location to prevent this. However, it apparently doesn't help.
CityViewController can also open SMS composer as its child.
The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.
The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.
In addition, you can check for UINavigationController and ask for its topViewController or even check for UITabBarController and ask for selectedViewController . This will get you the view controller that is currently visible to the user.
To get the currently visible view you can use:
[self.navigationController visibleViewController];
So the reply to original question: How do i get current active view controller?
The answer lies in [self.navigationController presentedViewController]
instead of topViewController or anything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With