Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fergusjk

macrumors member
Original poster
Aug 23, 2010
44
0
Ayrshire Coast, Scotland
I'm creating a tabbar app that has 4 views (and rising).

I want to be able to click a UIButton on view 1 and the app shall go to view 3 in the exact same way as though the user had touched the the third tab whilst in view 1.

Please don't respond with the obvious "why wouldn't the user just touch tab 3" as I'm a noob and trying to implement this as a way of understanding how much control I can exercise over the tab bar controller.

There must be an easy way to get a handle on the tabbar controller, then call a method or do something with that handle so that the app moves along to different views (tabs)?

Thanks in Advance.
 

ulbador

macrumors 68000
Feb 11, 2010
1,554
0
tabBarController.selectedIndex = 0;
tabBarController.selectedIndex = 1;
tabBarController.selectedIndex = 2;
tabBarController.selectedIndex = etc;
 

fergusjk

macrumors member
Original poster
Aug 23, 2010
44
0
Ayrshire Coast, Scotland
Perfect!!!

I didn't even realise a handle for the tab bar controller was created in the appDelegate.

So, to be clear, I just added this method to the appDelegate
-(void) changeView{
tabBarController.selectedIndex = 2;
}

And called that from my first view and it changed straight away.

Thanks ulbador.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Probably don't even need to put the method in appDelegate; you can keep it in your view1 controller. Then do something like:
Code:
-(void) changeView{
    ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.tabBarController.selectedIndex = 2;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.