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

  • 相关阅读:
    后端Golang+前端React架构开发案例
    Vim技巧大全
    Draggable Modal dialog in Bootstrap
    Github.com的镜像站
    kettle之excel上传数据库
    自定义函数之分割函数
    jmeter 压测 ActiveMq 消息队列
    SQL---查找+删除重复记录
    异常值检测(Outlier Detection)
    使用u盘在pc上安装centos7(安装停留在dracut:/#的处理)
  • 原文地址:https://www.cnblogs.com/yintingting/p/4540318.html
Copyright © 2011-2022 走看看