austin austin - 1 year ago 59
Objective-C Question

How do I pass data from a tab bar controller to one of its tabs?

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.


p.s. i'm new and have so far depended on storyboard for viewcontroller transitions

Answer Source

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!