views:

35

answers:

1

Hi, 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!

+1  A: 

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.

mvds
I'm not using a tab bar controller it's just a UIViewController because it has all custom buttons with varying placement and graphics.
Hippocrates
In that case, keep an NSArray of the views, and keep a state variable telling which view is current. Then create two functions like those proposed above. Make a function `setSelectedIndex` which removes the current view, and adds the new view.
mvds