Search code examples
objective-ciosuinavigationcontrolleruitabbar

The code for a button to change views (with TabBarController)


I have a basic app with a TabBarController. I have three tabs, and all of them have .xib files, which each tab loads. Each tab also has a NavigationbarController, so it has a Navigation bar with the title on top. Now I want to make a button (actually one on every tab, doesn't matter), that loads another view (it should flip over, but that also does not matter right now). How to code that? I already have this code, but something is wrong with the window from each class (I also don't know in which action to put it.):

- (void)flipToBack {
OptionsViewController *optionsView= [[OptionsViewController alloc] initWithNibName:@"OptionsView" bundle:nil];
[self setSecondViewController:optionsView];
[optionsView release];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
[viewController (?).view removeFromSuperview];
[self.window addSubview:[OptionsViewController view]];
[UIView commitAnimations];

}

Where OptionsViewController is my .h and .m file for the OptionsView. the ViewController is where I get stuck. What controller should I put in there? Also: in which file should I put this? (Probably in the current view), I get stuck here.

My views look as following:

-View
  -TabBar
    -Navigation Bar
      -TabBar item
        -NavigationBar Button
      -View controller
    -Navigation Bar
      -TabBar item
        -NavigationBar Button
      -View controller
    -Navigation Bar
      -TabBar item
        -NavigationBar Button
      -View controller

Solution

  • Do you want to transition to a whole new view/view controller? If so, try - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated in your navigation view controller.