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:calculat开发者_开发百科or1];}
please Help and Suggest
Note that you're creating a new Calculator
instance on your button click handler. What you probably want to do is change the tab on an existing view controller, and not to create a new one.
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 in the link.
精彩评论