bharath
bharath

Reputation: 953

Tab bar element onclick IOS

I have a master utility application embedded in a tab bar. Now, for this tab bar, i have the following.

@interface MainTabViewController : UITabBarController< UITabBarControllerDelegate>{
}
@end

@implementation MainTabViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    NSLog(@"One");
    if(self.tabBarController.selectedIndex==1)
    {
        NSLog(@"clicked");
    }

    if (self.tabBarController.selectedIndex==2) {
        NSLog(@"Helo");
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tabBarController.delegate = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

The code is not reaching the didSelectViewController at all. I am new to IOS. Could anyone plz guide where i am going wrong??

Upvotes: 0

Views: 204

Answers (1)

Anurag Kabra
Anurag Kabra

Reputation: 444

Add delegate method to the UITabBarController

either using storyboard (if you are using)

or as it is UITabBarController do using

self.delegate = self ; 

Upvotes: 2

Related Questions