I have a UITabBarController set up in storyboard. I want to pass a dictionary of data from the tab bar controller for use in the appropriate child tab, which is a standard UIViewController.
This seems like a long questions to answer, but I really don't know where to start. I'm looking for the easiest way through this. Must I make the tabs function programmatically? Pointing me towards any useful developer documentation would also be much appreciated.
-Austin
p.s. i'm new and have so far depended on storyboard for viewcontroller transitions
To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.
We open up our Main. storyboard and go ahead and delete the pregenerated view controller. Dragging a "Tab Bar Controller" from the Object Library into the storyboard automatically creates two view controllers that are already in the tab bar controller's array of view controllers.
It took a couple of days, but I discovered a simple solution. In my TabBarController's viewDidLoad method, I can access and set attributes of my the tabbed subviews using
[[self viewControllers] objectAtIndex:0]
or whatever index you wish to access.
Saving that as an instance of my tab1_viewController gives me a pointer to the object, from which I can get and set my property values. This was initially unclear because storyboard created the tab_viewController objects for me. I never had a chance to initialize them the way I wanted to!
Your best bet is to use notifications.
In your tab bar, you would do this:
NSDictionary *myDictionary; // Populate this with your data. // Fire the notification along with your NSDictionary object. [[NSNotificationCenter defaultCenter] postNotificationName:@"Some_Notification_Name" object:myDictionary];
Then in your child tab ViewController, you would "listen" for that notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"Some_Notification_Name" object:nil]; - (void)handleNotification:(id)object { // Use your NSDictionary object here. }
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