zoukankan      html  css  js  c++  java
  • UITabBarController相关之tabBar文字不显示

    1.在用tabBarController管理控制器的时候,出现了下面的问题

    对应的代码:

     JingHuaController *jinghuaVC = [[JingHuaController alloc]init];
     ZuixinViewController *zuiXinVC = [[ZuixinViewController alloc]init];
     //FaTieController *faTieVC = [[FaTieController alloc]init];
     AttentionController *attentionVC = [[AttentionController alloc]init];
     WoViewController *woVC = [[WoViewController alloc]init];

    //添加控制器,设置对应tabItem的图片

     [self addChild:jinghuaVC image:kImage(@"tabBar_essence_icon") selectedImage:kImage(@"tabBar_essence_click_icon")];

        [self addChild:zuiXinVC image:kImage(@"tabBar_new_icon") selectedImage:kImage(@"tabBar_new_click_icon")];

        //[self addChild:faTieVC image:kImage(@"tabBar_publish_icon") selectedImage:kImage(@"tabBar_publish_click_icon")];

        [self addChild:attentionVC image:kImage(@"tabBar_friendTrends_icon") selectedImage:kImage(@"tabBar_friendTrends_click_icon")];

        [self addChild:woVC image:kImage(@"tabBar_me_icon") selectedImage:kImage(@"tabBar_me_click_icon")];

    - (void)addChild:(UIViewController *)ViewController image:(UIImage *)image selectedImage:(UIImage *)selectedImage{

        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:ViewController];

        [self addChildViewController:nav];

        ViewController.tabBarItem.image = image;

        ViewController.tabBarItem.selectedImage = selectedImage;

    }

    //控制器中的代码

    @implementation AttentionController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.title = @"关注";  //在控制器中设置文字,问题就出在这里。我们知道,控制器的view是懒加载,即需要显示的时候才会加载。虽然开始我通过addChildController方法把相应controller加入到tabBarController中,但是界面出来时,只会显示第一个控制器的view,所以其他几个controller页面并没有显示,所以没有加载。所以它们的viewDidLoad方法并没有调用,“self.title = @"关注"根本没有执行,tabBar上怎么会显示呢?

    解决办法:在添加控制器的时候,就一一设置tabBarItem.title就可以啦!

    }

     @end

  • 相关阅读:
    CSS 的层叠上下文是什么
    BFC原理解析
    从 (a==1&&a==2&&a==3) 成立中看javascript的隐式类型转换
    IIFE中的函数是函数表达式,而不是函数声明
    Virtual DOM 真的比操作原生 DOM 快吗?
    解决for循环里获取到的索引是最后一个的问题
    bzoj4161: Shlw loves matrixI
    [NOI2007]生成树计数环形版
    bzoj1494: [NOI2007]生成树计数
    bzoj1964: hull 三维凸包
  • 原文地址:https://www.cnblogs.com/yintingting/p/4540318.html
Copyright © 2011-2022 走看看