Reputation: 2540
my app has a menu with an assortment of buttons at the bottom, each button inserts a new subview from one of my xibs, underneath the menu. The views have an order they are supposed to go in(think powerpoint presentation) though the user can touch a certain button to go to any of them.
There are also next and previous buttons.
I am wondering how I should reference the views in my menu's view controller such that I can insert the proper "next" and "previous" view, which of course depends on which one is currently showing. Also I need to remove the current subview after inserting the new one, whichever that may be.
Thanks!
Upvotes: 0
Views: 82
Reputation: 47034
If you are using a UITabBarController
, you can for example just call
[self.tabBarController setSelectedIndex:2];
to go to the 3rd screen. (note that index 0 is the first screen)
So if you hook up buttons to for example
-(IBAction)next:(id)source
{
[self.tabBarController setSelectedIndex:[self.tabBarController selectedIndex]+1];
}
-(IBAction)prev:(id)source
{
[self.tabBarController setSelectedIndex:[self.tabBarController selectedIndex]-1];
}
you're almost there. This assumes that you have a UITabBarController as the parent of the viewcontroller you put this in. If you subclassed UITabBarController, just use self
instead of self.tabBarController
.
Upvotes: 1