简体   繁体   English

tabBarController是零; 无法更改viewDidLoad上的selectedIndex

[英]tabBarController is nil; can't change selectedIndex on viewDidLoad

I have a UITabBarController like this: 我有一个像这样的UITabBarController:

/*SomeTabBarController.h*/
@interface SomeTabBarController: UITabBarController
@end

and in the SomeTabBarController.m i want to change the active tab on viewDidLoad SomeTabBarController.m中我想更改viewDidLoad上的活动选项卡

-(void)viewDidLoad
{
  [super viewDidLoad];
  self.tabBarController.selectedIndex = 2;
}

However, tabBarController is nil . 但是,tabBarController是 What am i missing? 我错过了什么? I have a navigation controller and segue push to the tab bar controller... 我有一个导航控制器和segue推送到标签栏控制器...

Thx 谢谢

Try this: 尝试这个:

self.selectedIndex = 1;

You are the tabBarController :) 是tabBarController :)

You can't change a property of an item that doesn't exist yet :) try changing the selected tab in viewWillAppear or viewDidAppear. 您无法更改尚不存在的项目的属性:)尝试更改viewWillAppear或viewDidAppear中的选定选项卡。

Or if you are able to create your tab controller in code on viewDidLoad, then you could simply set selected index on the next line. 或者,如果您能够在viewDidLoad上的代码中创建选项卡控制器,那么您可以在下一行设置所选索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM