iOS tabBarController在AppDelegate中检测选定的索引

时间:2015-02-22 15:23:20

标签: ios objective-c uitabbarcontroller uitabbar appdelegate

AppDelegate.h *****

@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate,UITabBarDelegate>

AppDelegate.m *****

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex);
}

这种方法不起作用吗? 我想在单击标签栏项目时滚动顶部 请帮助:)

1 个答案:

答案 0 :(得分:1)

您只需在第一个viewController的viewDidLoad方法中添加此行:

self.tabBarController.delegate = ((AppDelegate *)[UIApplication sharedApplication].delegate);