UITabBarController set action to specific tab
I would like to set an action to specific tab
on UITabBarController
. How can I do this?
See my code below:
Update with code
@interface AccountTabViewController : UIViewController <UITabBarControllerDelegate, UITabBarDelegate>
{
IBOutlet UITabBarController *tabController;
IBOutlet UITabBar *tabBar;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if(tabBarController.selectedIndex == 0)
{
[self dismis开发者_如何学运维sModalViewControllerAnimated:YES];
}
}
It never get into the method! Please help.
See UITabBarDelegate reference and UITabBarControllerDelegate Protocol Reference.
The method you are looking for is
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
}
or one of these:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
}
Also, UITabBarController reference.
Look at UITabBarControllerDelegate method:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0)
{
// First Tab is selected do something
}
}
精彩评论