Reputation: 744
I would like to know how I can find the current view controller if I have a UITabBarController
and within that TabBarController I have 4 different UINavigationController
s and then that NavigationController obviously has the stack of view controllers. In my app delegate I am trying to find out this information so that I can stop an in-app push notification from appearing. So I am looking to do something like:
if (self.currentViewController != self.chatViewController) {
//Show the notification everywhere else except here(here being self.chatViewController)
}
Upvotes: 0
Views: 856
Reputation: 564
Try doing this:
UITabBarController *tabBarControler = (UITabBarController*)self.window.rootViewController;
UINavigationController *navController = [[tabBarControler viewControllers] objectAtIndex:<selected_index>];
NSArray *navViewControllers = [navController viewControllers];
You can check for the present viewController like this.
if (navController.topViewController != self.chatViewController) {
//Show the notification every else except here(here being self.chatViewController)
}
Edit by @kylecman
What I ended up doing was using the tabbarcontroller and navigation controller instances and not using the array(have not found the need for that)
and then I prepared an IF statement for the viewController's class
if (![navController.topViewController isKindOfClass:[ChatView class]] && ![navController.topViewController isKindOfClass:[MessagesViewController class]]) {
Upvotes: 3