从一个tabbarController 跳转到另一个 tabbarController

在项目中通常会遇到一下场景: 从一个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];

    

扫描二维码关注公众号,回复: 938945 查看本文章

    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



demo: https://github.com/YST521/tabbarJump.git

猜你喜欢

转载自blog.csdn.net/yst19910702/article/details/79584401