码迷,mamicode.com
首页 > 移动开发 > 详细

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 的解决办法

时间:2015-12-08 20:13:23      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar  的解决办法

问题:iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar

1.自定义代码:

- (void)viewWillAppear:(BOOL)animated

{

    [super  viewWillAppear:animated];

    

    // 删除系统自动生成的UITabBarButton

    [self removeTabBarButton];

}

 

-(void) removeTabBarButton {

    // 删除系统自动生成的UITabBarButton

     for (UIView *child  in self.tabBar.subviews) {

         if ([child isKindOfClass:[UIControl  class]]) {

            [child  removeFromSuperview];

        }

    }

}

 

/**

 *  初始化tabbar

 */

- (void)setupTabbar

{

     HYTTabBar *customTabBar = [[HYTTabBar  alloc] init];

    customTabBar.frame =  self.tabBar.bounds;

    customTabBar.delegate =  self;

    [self.tabBar  addSubview:customTabBar];

     self.customTabBar = customTabBar;

}

 

2.pop代码:

[self.navigationController popToViewController:strongSelf.navigationController.childViewControllers[1]  animated:YES];

 

3.结果:

 

 技术分享

解决方法:

1. pop的时候  发送通知(注意是从  要pop回带有tabber的那个VC控制器发出通知)

 NSNotification *notification =[NSNotification notificationWithName:@"HYTPopViewControllerNotification" object:nil userInfo:nil];

  [[NSNotificationCenter defaultCenter] postNotification:notification];

 

 

2. 在自定义的tabcontroller 的viewdidload方法中注册通知,调用removeTabBarButton方法删除系统自带的就可以了

- (void)viewDidLoad {

    [super viewDidLoad];

    

    // 初始化tabbar

    [self setupTabbar];

    

    //.../

 

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HYTPopViewControllerNotification) name:@"HYTPopViewControllerNotification" object:nil];

}

 

-(void) HYTPopViewControllerNotification {

    // 删除系统自动生成的UITabBarButton

     for (UIView *child  in self.tabBar.subviews) {

         if ([child isKindOfClass:[UIControl  class]]) {

            [child  removeFromSuperview];

        }

    }

}

ps我尝试过连续调用几个popviewcontroller的方法来替代poptoviewcontroller,结果正常。

这说明popviewcontroller 和 poptoviewcontroller 的实现至少在自定义tabbar上是有本质差别的。

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 的解决办法

标签:

原文地址:http://www.cnblogs.com/sunxianglong/p/5029920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!