How to change TabBarController index and call method
I have a UIButton in one of my tabBar view's controller and I want that button to change the tabBar selectedIndex and call that selectedIndex's controller method.
Example: My button is selectedIndex 3. When the user clicks the button, I want to change the selectedIndex to 0 and call a method in that selectedIndex's controller.
Is this possible? If so, how?
Th开发者_如何学JAVAanks in advance!
This is how you can switch to a different tab:
- (IBAction)buttonPressed:(id)sender
{
self.tabBarController.selectedIndex = 0;
/* Running method declared in FirstViewController */
FirstViewController *firstView = [[FirstViewController alloc] init];
// call methods here
[firstView methodName];
[firstView release];
}
Ya you can do it easily....just use this in your button event method
[self.tabBarController setSelectedIndex:3];
精彩评论