adit
adit

Reputation: 33674

setting a tab bar controller view controller programmatically

Is there a way to set the view controller on the tab bar controller programmatically? Lets say I want it to show the second's tab view controller programmatically, is there a way to do that?

This is useful if I logout from my app, which is done from my third tab, when the user logins it should start from the 1st tab again. When I logout I am just showing a present modal view controller on top of what the previous view is, so I somehow needs to reset it again to the first tab bar without re-initializing it all over again.

The issue is now how do I do this?

Upvotes: 0

Views: 4028

Answers (3)

Teodor Kostov
Teodor Kostov

Reputation: 313

Have a look at the reference on UITabBarController. Work with selectedIndex and selectedViewController.

Upvotes: 0

Gypsa
Gypsa

Reputation: 11314

Hi ye you can do this

You might have tabbarcontroller object in appDelegate.

So on logout button

make object on your appDelegateClass and do this:-

appDelegate.tabBarController.selectedIndex=0;

Upvotes: 1

Mark Armstrong
Mark Armstrong

Reputation: 839

From Apple's documentation it looks to me like you could just call the following two functions:

    [myTabBarController setSelectedIndex:0];
    [myTabBarController setSelectedViewController:[myTabBarController.viewControllers objectAtIndex:0]];

Upvotes: 2

Related Questions