简体   繁体   中英

tabBarController is nil; can't change selectedIndex on viewDidLoad

I have a UITabBarController like this:

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

and in the SomeTabBarController.m i want to change the active tab on viewDidLoad

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

However, tabBarController is nil . What am i missing? I have a navigation controller and segue push to the tab bar controller...

Thx

Try this:

self.selectedIndex = 1;

You are the tabBarController :)

You can't change a property of an item that doesn't exist yet :) try changing the selected tab in viewWillAppear or 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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