在项目中通常会遇到一下场景: 从一个tabbarController 的item 跳转到 另一个item 这个只要获取到当前tabbar就可以切换。是获取同一个 不是创建一个;
self.tabBarController.selectedIndex = 2;
场景二 ,从tabbarController A t跳转到 tabbarController B 这个一般是app两个不同功能大模块切换。或者一个APP嵌套子App.
这个可以通过window的根控制器切换达到效果。当然一般一个App嵌套第三App一般采用web.或者weex React Native 。支付宝飞猪,当手机装有飞猪 会先选择打开飞猪APP没有装,web版。
//A tabbarController 跳转到 B tabbarController
BtabbarController *tabbarVC = [[BtabbarController alloc]init];
AppDelegate *appdelegateE = (AppDelegate*)[UIApplication sharedApplication].delegate;
appdelegateE.window.rootViewController = tabbarVC;
tabbarVC.selectedIndex = 0;
// B tabbarController 返回到 A tabbarController
AppDelegate *appDelegatE = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegatE.window.rootViewController = appDelegatE.aTabbarVC;
//注意的是在
AppDelegate 中暴露出主tabbarController 便于后面切换获取。
#import <UIKit/UIKit.h>
#import "AtabbarController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,strong)AtabbarController *aTabbarVC;
@end