0
votes

I have 3 viewcontroller in tabbar. I am loading tabbar from appdelegate. Now I want to make an event when user change viewcontroller from tabbar. For that I have wrote delegate method didselectitem in appdelegate and set delegate in my viewcontroller. But delegate method is not called.

In my viewcontroller I am writing this:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    NSLog(@"tabbar is %@",tabBar.selectedItem);

}

in viewdidload:

MyAppDelegate.tabBar.delegate=self;
1
Do you mean tab bar controller delegate? -tabBarController:didSelectViewController:? - Leo Natan
Show the code for where you set the delegate. - rdelmar
Hey put your code, so we can able to know what is wrong in your code. - Nirmalsinh
@LeoNatan you are correct but vivek has implemented the didSelectItem which is UITabBarDelegate method. The solution should be to implement the tabBarController:didSelectViewController: method. - Suhit Patil
@vivek as suggested by Leo Nathan, implement the UITabBarControllerDelegate and use the tabBarController:didSelectViewController: to know which viewController got selected. - Suhit Patil

1 Answers

2
votes

Make sure to set the delegate of the UITabBarController and not the tab bar itself. Also, make sure to implement the correct delegate method: tabBarController:didSelectViewController:

More information in the UITabBarControllerDelegate documentation.