UITabBarController启动后只能显示一个标签

个性小资 2016-11-01 05:27:43
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语言
...全文
504 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
上官风雨419 2016-11-16
  • 打赏
  • 举报
回复
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];
个性小资 2016-11-07
  • 打赏
  • 举报
回复
引用 2 楼 qq_23613747 的回复:
sender.tabBarItem.image = [UIImage imaged:name]; sender.tabBarItem.selectedImage=[UIImage imaged:name]; 要设置tabBarItem的两种图片模式
按照您的方法试了,还是刚启动的时候不显示第二个图标
目生鱼 2016-11-03
  • 打赏
  • 举报
回复
sender.tabBarItem.image = [UIImage imaged:name]; sender.tabBarItem.selectedImage=[UIImage imaged:name]; 要设置tabBarItem的两种图片模式
个性小资 2016-11-03
  • 打赏
  • 举报
回复
求助啊,有高手出没么?

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧