我想在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];
}
}
它永远不会进入方法!请帮忙。
答案 0 :(得分:7)
请参阅UITabBarDelegate reference和UITabBarControllerDelegate Protocol Reference 您正在寻找的方法是
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
}
或其中之一:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
}
答案 1 :(得分:4)
查看UITabBarControllerDelegate方法:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0)
{
// First Tab is selected do something
}
}