I have created tabbar in storyboard .and i am trying to change default tab bar programmatically using following code.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"TAB"])
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBar = [storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
tabBar.selectedViewController = [tabBar.viewControllers objectAtIndex:1];
}
}
But its not working.How i can do it? its not working at all.
Also i want to go back to home view controller when user select first tab.how we can achieve this functionality.
A tab bar controller is a powerful UI component for iOS apps. It's a container view, and you use it to group view controllers together. They give your app's user access to the most important screens of your app.
From the current selected view controller you can change tab selected index using code below.
[self.tabBarController setSelectedIndex:1];
To add Tab bar controller to viewcontrollers hirarchy IF YOU ARE USING NAVIGATION AS BASE then you can use:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBar = [storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
tabBar.selectedViewController = [tabBar.viewControllers objectAtIndex:1];
[self.navigationController pushViewController:tabBar animated:BOOL];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With