iOS的初学者,刚学着用UITabBarController做个很简单的小例子,就出现了问题,还请大家帮忙创建了两个ViewController文件,一个是ViewController1,一个是ViewController2,在里面就设置了,TabBar的图标和文字
    self.title = @"第一页";
    self.tabBarItem.image = [UIImage imageNamed:@"01"];
    [self.view setBackgroundColor:[UIColor blueColor]];
第二页也一样AppDelegate中初始化了两个ViewController,和设置启动时先启动tabBarController
UIViewController *viewController1 = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
    UIViewController *viewController2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
    
//    初始化选项卡控制器
    self.tabBarController = [[UITabBarController alloc] init];
//    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController2,viewController1, nil];(用了两种写法)
    self.tabBarController.viewControllers = @[viewController1,viewController2];
    
    self.window.rootViewController = _tabBarController;
出来的结果都是这样的:只出来了一个,第二个显示不出来,但是发现点击一下第二个位置所在,就能显示出来了启动的时候加了个断点,发现第一次启动时viewController2的信息并没有加载到请问大家这是什么问题,顺便说下我用的是xcode8.1,OC语言

解决方案 »

  1.   

    sender.tabBarItem.image = [UIImage imaged:name];
     sender.tabBarItem.selectedImage=[UIImage imaged:name];
    要设置tabBarItem的两种图片模式
      

  2.   

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        UITabBarController *tab = [[UITabBarController alloc]init];
        OneViewController *one = [[OneViewController alloc]init];
        one.tabBarItem.title =@"one";
        TwoViewController *two = [[TwoViewController alloc]init];
        two.tabBarItem.title = @"two";
        ThreeViewController *three = [[ThreeViewController alloc]init];
        three.tabBarItem.title = @"three";
        tab.viewControllers = @[one,two,three];
        self.window.rootViewController = tab;
        [self.window makeKeyAndVisible];