UITabBarController将操作设置为特定选项卡

时间:2011-09-09 16:00:45

标签: iphone objective-c uitabbarcontroller

我想在tab上针对特定UITabBarController设置操作。我怎样才能做到这一点?  请参阅下面的代码: 使用代码更新

@interface AccountTabViewController : UIViewController <UITabBarControllerDelegate, UITabBarDelegate>
{
    IBOutlet UITabBarController *tabController;
    IBOutlet UITabBar *tabBar;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if(tabBarController.selectedIndex == 0) 
    {
        [self dismissModalViewControllerAnimated:YES];
    }
}

它永远不会进入方法!请帮忙。

2 个答案:

答案 0 :(得分:7)

请参阅UITabBarDelegate referenceUITabBarControllerDelegate Protocol Reference 您正在寻找的方法是

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
}

或其中之一:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
}

另外,UITabBarController reference

答案 1 :(得分:4)

查看UITabBarControllerDelegate方法:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
   if (tabBarController.selectedIndex == 0) 
   {
     // First Tab is selected do something
   }
}