I have a tab bar that is created programmatically and I'm having difficulties initializing a storyboard associated with a view.
I'm able to load the view successfully in the tab bar without the storyboard (see code below) but the view is only partially showing because some of the UI components are in the storyboard.
The name of my storyboard is MainStoryboard and I set the storyboard view identifier to SettingsViewController.
How can I initialize my storyboard for SettingsViewController in the code below?
- (void)createTabBarItems {
tabBarController = [[UITabBarController alloc] init];
settingsViewController = [[SettingsViewController alloc] init];
UINavigationController *sett = [[[UINavigationController alloc]
initWithRootViewController: settingsViewController] autorelease];
[sett.tabBarItem setTitle:@"Settings"];
[sett.tabBarItem setImage:[UIImage imageNamed:@"settings.png"]];
[tabBarController setViewControllers:
[NSArray arrayWithObjects:sett, sett, sett, sett, nil]];
}
Open Main. storyboard and select the map view controller. From Xcode's Editor menu, choose Embed In → Tab Bar Controller. This will add the map view controller to the view controllers array of a new tab bar controller.
Add a new Tab Bar ItemDrag View controller into the storyboard. Drag Tab Bar Item into the newly created view controller, it will sit at the same level of the View .
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.
If you want to initialize the view controller as in the storyboard you have to use the storyboard methods instead of allocating the view controller directly:
// load the storyboard by name
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
// either one of the two, depending on if your view controller is the initial one
settingsViewController = [storyboard instantiateInitialViewController];
settingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];
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