如何监听Tabbar的点击
如果不是自定义的Tabbar
- 实现
UITabBarController
的代理方法tabBarController: didSelectViewController:
, 每次Tabbar被点击了都会来到这个代理方法
- 在这个代理方法中发送通知
- 在需要监听Tabbar点击的控制器中监听上面发出的通知
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[[NSNotificationCenter defaultCenter] postNotificationName:AHTabBarDidSelectNotification object:nil userInfo:nil];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tabBarSelect) name:AHTabBarDidSelectNotification object:nil];
- (void)tabBarSelect{
// 如果是连续选中2次, 直接刷新
if(self.lastSelectedIndex == self.tabBarController.selectedIndex && self.view.isShowingOnKeyWindow