Here's my setup that worked:
- Setup Segue:
- Setup View Controller with segue to Tab Bar Controller with 2 child View Controllers in Storyboard
- Specify segue identifier (
tab
)
- Setup Classes in Storyboard:
- View Controller class =
ViewController
- Tab Bar Controller class =
TabBarController
- Tab Bar Controller Child View Controller class =
TabsViewController
(shared between both)
- View Controller class =
Setup
labelString
property in Tab Bar Controller:In
TabBarController.h
:@property (nonatomic, strong) NSString *labelString;
In
TabBarController.m
:@synthesize labelString;
Setup
prepareForSegue
method inViewController.m
:#import "TabBarController.h" ... -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"tab"]){ TabBarController *tabBar = [segue destinationViewController]; [tabBar setLabelString:[NSString stringWithFormat:@"This has been set"]]; } }
Setup
UILabel
s for Child Tab Bar View Controllers.- Drag default
UILabel
controls into both child View Controllers Create property in
TabsViewController.h
:@property (nonatomic, strong) IBOutlet UILabel *label;
Hook
5.1
and5.2
up in Storyboard
- Drag default
Setup
ViewDidLoad
method inTabsViewController.m
:#import "TabBarController.h" ... @synthesize label; ... - (void)viewDidLoad { [super viewDidLoad]; TabBarController *tabBar = (TabBarController *)self.tabBarController; label.text = [NSString stringWithFormat:@"Tab %i: %@",[tabBar.viewControllers indexOfObject:self],tabBar.labelString]; }
Now clicking on the 1st and 2nd tabs will have the labels display Tab 0: This has been set
and Tab 1: This has been set
, respectively.