因項(xiàng)目需求,需要將底部Tabbar點(diǎn)擊后達(dá)到這樣的效果:點(diǎn)擊首頁后,要求顯示最初的首頁界面,而非二級、三級界面等。
研究了下TabbarController的代理方法,找到了解決辦法。思路:window的根視圖是UITabBarController,UITabBarController的子viewControllers中放的是UINavgationController,所以,找到底部item的點(diǎn)擊事件,將UINavgationController ?Pop 到navgationController根視圖即可,(前提是viewControllers中放的是UINavgationController)
1.在APPDelegate中設(shè)置UITabBarController的代理
2.遵循協(xié)議,實(shí)現(xiàn)協(xié)議的方法
3.通過UINavgationController ?Pop 到navgationController的根視圖
1.
@interface AppDelegate ()
/**
?*? @discussion? 設(shè)置TabbarController,在此方法中設(shè)置TabbarController的代理
?*/
2.
-(void)setupTabBarController {
? ? self.window.rootViewController.view.alpha = 0;
? ? RootTabViewController *tabbar = [[RootTabViewControlleralloc] init];
? ? self.window.rootViewController = tabbar;
? ? tabbar.delegate =self; ? ?// 設(shè)置代理
}
3.
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
? ??BaseNavigationController *base = (BaseNavigationController *)viewController;
? ? ?[base popToRootViewControllerAnimated:NO];
? ??/* 可根據(jù)項(xiàng)目需求自行修改
? ? if (tabBarController.selectedIndex == 0) {
? ? }else if (tabBarController.selectedIndex == 1){
? ? }else if (tabBarController.selectedIndex == 2){
? ? }else if (tabBarController.selectedIndex == 3){
? ? }else if (tabBarController.selectedIndex == 4){
? ? }
? ? */
}