首页 > 代码库 > 关于两个tabbar之见的跳转

关于两个tabbar之见的跳转

        最近项目需要,我们需要使用两个tabbar,因为之前一直是使用单个tabbar,突然来了两个tabbar,我有点没有思路了.

特别是关于两个tabbar之见的跳转,我在网上查了一下,发现资料非常少.后来经过一番苦思冥想,终于找到解决方法了.



       我是这样解决的,就是在ATabBar中写了一个UIButton,然后通过Push跳转到第二个BTabBar页面上,

- (void)viewDidLoad

{

    [superviewDidLoad];

    self.navigationItem.title =@"首页";

   //在ATabBar中写了一个UIButton

    UIButton * button = [UIButtonbuttonWithType:UIButtonTypeSystem];

    button.frame =CGRectMake(100,100, 100,100);

    [button setTitle:@"明星"forState:UIControlStateNormal];

    [button addTarget:selfaction:@selector(didClickButtonAction)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:button];

}


- (void)didClickButtonAction

{

    //第二个BTabBar

    StarTabBarViewController * starTabBar = [[StarTabBarViewControlleralloc]init];

    //隐藏tarBar

     self.tabBarController.tabBar.hidden = YES;

    //隐藏导航栏

    self.navigationController.navigationBarHidden =YES;

    [self.navigationControllerpushViewController:starTabBar animated:NO];

}

其中,因为第二个BTabBar上面也有TabBar,也有导航栏,所以我们需要把第一个TabBar的导航条跟TabBar隐藏了.


当我完成这一步,我发现问题来了,我回不去了,我pop回不到第一个ATabBar了.

这个时候,我尝试各种pop方法,但是回不去,后来我好好整理了一下思路,发现Push的是starTabBar,那么pop回去的也应该是starTabBar,而不是我们常见的

  [self.navigationControllerpopToRootViewControllerAnimated:YES];(这样是错误的)

正确的写法是:

 UIBarButtonItem * leftItem = [[UIBarButtonItemalloc]initWithTitle:@"返回"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(didClickLeftItemAction)];

    

    self.navigationItem.leftBarButtonItem = leftItem;


- (void)didClickLeftItemAction

{

    [self.tabBarController.navigationControllerpopToRootViewControllerAnimated:YES];(这样才正确)

}


好吧,我解决问题了,希望能给大家带来帮助.







关于两个tabbar之见的跳转