點(diǎn)擊底部Tabbar某個(gè)item,返回到其對應(yīng)的初始頁

因項(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){


? ? }

? ? */

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容