You could use the NSNotificationCenter to post notifications to your View Controllers when the Tab Bar gets tapped. To set up this mechanism you have to do this in your first view Controller.
#import "FirstViewController.h"
@interface FirstViewController ()<UITabBarControllerDelegate>
@end
@implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.tabBarController.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (((UINavigationController *)viewController).topViewController == self) {
UIViewController *newViewController = [UIViewController new];
[self.navigationController pushViewController:newViewController animated:NO];
NSLog(@"Push view controller first tab");
}else {
[[NSNotificationCenter defaultCenter]postNotificationName:@"tabBarControllerDidSelectViewController" object:((UINavigationController *)viewController)];
}
}
@end
In your the rest of your view controllers do the following
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didTabed:) name:@"tabBarControllerDidSelectViewController" object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
-(void)didTabed:(NSNotification *)notification
{
if ([[notification object] isKindOfClass:[UINavigationController class]]) {
UIViewController *selectedViewController = ((UINavigationController *)[notification object]).topViewController;
if (selectedViewController == self) {
UIViewController *newViewController = [UIViewController new];
[self.navigationController pushViewController:newViewController animated:NO];
NSLog(@"Push view Controller tap2");
}
}
}
@end
If you have any questions about this please don't hesitate to ask!
Hope this helps.