zoukankan      html  css  js  c++  java
  • iOS 解决自定义TabBar使用popToRootViewControllerAnimated重叠问题

    解决方法一:

    在自定义的NavigationController中添加如下代码:

     (void)viewDidLoad{  
        [super viewDidLoad];  
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeTabBarBtn) name:@"removeTabBarBtn" object:nil];  
    }  
      
    - (void)removeTabBarBtn  
    {  
    //    NSArray *tSubviews = self.tabBarController.tabBar.subviews;  
    //    for (int i = 0; i < tSubviews.count; i++) {  
    //        Class parentVCClass = [tSubviews[i] class];  
    //        NSString *className = NSStringFromClass(parentVCClass);  
    //        ALog(@"%d---%@",i, className);  
    //      
    //    }  
          
        for (UIView *tabBar in self.tabBarController.tabBar.subviews) {  
            if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) {  
                [tabBar removeFromSuperview];  
            }  
        }  
    }  
      
      
    -(void)dealloc  
    {  
        [[NSNotificationCenter defaultCenter]removeObserver:self name:@"removeTabBarBtn" object:nil];  
    }  

    并且在调用popToRootViewControllerAnimated方法的viewController中发出通知:

    [self.navigationController popToRootViewControllerAnimated:NO];  
    [[NSNotificationCenter defaultCenter] postNotificationName:@"removeTabBarBtn" object:nil userInfo:nil];  

    解决方法二:

    (该方法更为简单)苹果强大就强大在这里,他们已经预想到了。

    所以方法就是:遵循UINavigationController的代理,用代理方法解决该Bug,代码如下:

    设置代理:

    - (void)viewDidLoad{  
        [super viewDidLoad];  
        self.delegate = self;  
    }  
     

    实现代理方法:

     
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated  
    {  
        // 删除系统自带的tabBarButton  
        for (UIView *tabBar in self.tabBarController.tabBar.subviews) {  
            if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) {  
                [tabBar removeFromSuperview];  
            }  
        }  
    }  

    原文链接:iOS自定义TabBar使用popToRootViewControllerAnimated重叠问题解决

  • 相关阅读:
    图灵2010.05书讯
    上海.NET技术交流会
    图灵2010.07书讯
    高效模式编写者的7个习惯
    QRCode 二维码开源DLL
    javascript 复习
    关于反射技术
    数字签名与加密解密
    使用负载均衡技术建设高负载的网络站点
    dreamweaver cs5.5中的phonegap升级测试
  • 原文地址:https://www.cnblogs.com/guchunli/p/6709922.html
Copyright © 2011-2022 走看看