Trying to accomplish
Tap on the tabbaritem
and it will called the respective method on the tabbaritem VC
.
Issue
When I tap on tabbaritem2
it will call didSelectViewController
on tabbaritem2
and then the respective method. Then when I tap on tabbaritem3
it will still call the didSelectViewController
on tabbaritem3
and the respective method.
But when I switch back and tap on tabbaritem2
. It will still call the didSelectViewController
on tabbaritem3
and not didSelectViewController
on tabbaritem2
and the respective method doesn't work anymore
The issue without break
The issue with break
Question
How to properly set up the didSelectViewController
method so that when tabbaritem
is tapped it will call and load the method respectively?
Code
MyTabBarController.m (Do I need to do something here?)
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@"didSelectViewController... ");
// if ([viewController isKindOfClass:[UINavigationController class]]) {
// [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
// }
//=== I tried the following but it is not loading the method=====================
//if ([viewController isKindOfClass:[ClassNavigationController class]]) { // Here newViewController is the controller where the webview reload happens.
// [[[Classes alloc] init] reloadWebViewData]; // We create and instance for the new controller and call the delegate method where the reload works.
//}
//if (viewController == [tabBarController.viewControllers objectAtIndex:2]){
// [(UINavigationController *)viewController popToRootViewControllerAnimated:YES];
// [[[Classes alloc] init] LoadClasses];
//}else if (viewController == [tabBarController.viewControllers objectAtIndex:3]){
// [(UINavigationController *)viewController popToRootViewControllerAnimated:YES];
// [[[Gym alloc] init] handleRefreshGym:nil];
//}else{
//=== The following code will make viewWillAppear load on each tab bar item
//=== Without it, tapping on new tab bar item will not load viewWillAppear
// [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
//}
//=================================================================================
}
Classes.m
- (void)viewDidLoad {
[super viewDidLoad];
UITabBarController *tabBarController = (UITabBarController*)[UIApplication sharedApplication].keyWindow.rootViewController ;
[tabBarController setDelegate:self];
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@" Classes Called ");
if (viewController == [tabBarController.viewControllers objectAtIndex:2])
{
[(UINavigationController *)viewController popToRootViewControllerAnimated:YES];
[self handleRefresh:nil];
}else{
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
}
Gym.m
- (void)viewDidLoad {
[super viewDidLoad];
UITabBarController *tabBarController1 = (UITabBarController*)[UIApplication sharedApplication].keyWindow.rootViewController ;
[tabBarController1 setDelegate:self];
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@" Gym Called ");
if (viewController == [tabBarController.viewControllers objectAtIndex:3])
{
[(UINavigationController *)viewController popToRootViewControllerAnimated:YES];
[self handleRefreshGym:nil];
}else{
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
}