2011-09-09 62 views
1

我想將操作設置爲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]; 
    } 
} 

更新它從未進入方法!請幫忙。

回答

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

+0

由於某種原因,它沒有進入該方法! – HardCode

+0

請確保您的定義具有如下所示的:@interface iPhoneHomeViewController:UIViewController {}'。你必須使用委託方法將UITabBar/UITabBarController的委託屬性設置爲類。 – chown

+0

我用代碼更新了問題,沒有工作! – HardCode

4

看UITabBarControllerDelegate方法:

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