views:

291

answers:

1

Hello,

I am trying to create my own implementation of a tab bar, using a toolbar instead of a tabbar (to enable customization of the new "tab bar"). In order to achieve this, I need to have the ability to switch between views when a button is pressed.

Currently, my view consists of a tabBar subview, and a customView subview. The latter needs to be switched in the button callback of newTabBarController. Can anyone tell me how I might do this? Essentially I am wanting the same effect as presentModalViewController for the subview. Simply setting my view pointer to a different view doesn't work.

Here is some example code:

- (void)viewDidLoad{
  customView = selectedViewController.view;
  [self.view addSubView:customView];
  [self.view addSubView:newTabBarController.view];
}

- (void)buttonHandler:(id)sender {
  NewViewController newController = [[NewViewController alloc] init];
  // what to do now??
}

To be clear: the newTabBarController does not inherit from UITabBarController. It subclasses UIViewController.

A: 

If you plan on keeping those views around, I'd add them all to the superview and use bringSubviewToFront: and sendSubviewToBack: to manage which one the user sees.

//what to do now??
[self.view addSubView:newController.view];
[customView sendSubviewToBack];

From the iPhone Application Programming Guide:

To reorder existing subviews inside their parent, call the bringSubviewToFront:, sendSubviewToBack:, or exchangeSubviewAtIndex:withSubviewAtIndex: methods of the parent view. Using these methods is faster than removing the subviews and reinserting them.

Art Gillespie
Thanks, this solution will suffice for now. I can't help but feel that a UINavigationController should be used here.
MM