iphoneobjective-cios4uitabbarcontroller

iPhone: on button click Tab does not change


Hi I am not able to change Tab on button click so what could be the problem? Here is the code. I have connected all outlets properly.

 -(IBAction) BackPressed :(id) sender  
{

 Calculator *calculator1 = [[Calculator alloc] initWithNibName:@"Calculator" bundle:nil];

 [self.tabBarController setSelectedIndex:2];

 [self.tabBarController setSelectedViewController:calculator1];}

please Help and Suggest


Solution

  • You have to set viewcontrollers to tabbarcontroller initially. For example:

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navFirst,navsecond, navthird, navfourth, navfifth,nil];
    

    After that you can do the selectedIndex operation. Please check the questions and answer here.