Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

self.navigationController.tabBarController.selectedIndex not working

I have a UITabBarController which containing 4 different UIViewControllers.

On first tab there is a UINavigationViewController which contains its child UIViewController. without tapping the tab bar, i want to take user on second tab. For this I tried:

self.navigationController.tabBarController.selectedIndex = 1;

But it's not working.

ignore any mistake i am a newbie.

Thank you.

like image 955
S.J Avatar asked Nov 30 '22 14:11

S.J


2 Answers

if set delegate Try this:

self.selectedIndex = 1;

You are the tabBarController :)

like image 168
hossein hatami Avatar answered Dec 07 '22 00:12

hossein hatami


Do the following, before trying to change tab:

UITabBarController *tab = self.tabBarController;

if (tab) {
   NSLog(@"I have a tab bar");
   [self.tabBarController setSelectedIndex: 1];
}
else {
   NSLog(@"I don't have one");
}
like image 35
Rui Peres Avatar answered Dec 07 '22 00:12

Rui Peres