How-To: Jump between tabs using UITabBarController
Dec.31, 2008 in
Tech, iPhone Development
Sometimes you want to jump between tabs in your iPhone app programatically (ie you don’t want the user to have to touch the tab prior to displaying it). This is very easy to achieve:
self.tabBarController.selectedIndex = 3;
Where selectedIndex reflects the tab you wish to select (from left to right, starting at 0 for the first tab). The only thing to note, is that the UIViewController viewWillAppear method will not get called. So you may need to call this yourself, if you need to do something on the tab prior to it being displayed:
self.tabBarController.selectedIndex = 3; [self.tabBarController.selectedViewController viewDidAppear:YES];

April 19th, 2009 at 5:42 pm
I have been trying to perform the above coding statment from a NSThread, but cannot seem to get it to work. My setup: from within the App delegate I create an NSThread. When external events occur, I programatically try to go to a desired tab. However, nothing seems to work. Some sites indicate there may be issues when doing this from a thread. My NSThread passes the ‘this’ reference (the app delegate), hence I can get access to the UINavigationController and UITableViews, etc,.
Any ideas.
July 18th, 2009 at 7:50 am
Im having problems implementing this, could you post a tutorial or the code to understand it better?. Thanks in advance…
July 21st, 2009 at 6:52 am
Im also having problems implementing this piece of code, it gives me errors when i build it. Could you please post an example?
May 3rd, 2010 at 8:23 pm
Thanks…….helped me very much
May 5th, 2010 at 2:48 am
thnx for the code. its really help me a lot