jwknz
jwknz

Reputation: 6824

Passing data between the Tabs of a TabBarViewController

I have a UITabBarController based application and I want to pass data from one view to another. I am doing this in storyboard and I am just doing some testing, before bringing it into the main application.

I am just trying this with a NSString at the moment.

I am able to pass data to the VC in question when I use a modal transition using this code:

NSString *sendingString = @"This string has some content";    
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
NextViewController *nVC = (NextViewController *)[storyboard instantiateViewControllerWithIdentifier:@"goToNextVC"];

nVC.receivingString = sendingString;
[self presentViewController:nVC animated:YES completion:nil];

Now this pushes that VC up and passes it as I want it, but instead of pushing up the VC I want it to be pushed to another Tab Bar.

Now I can flick to the desired TabBar with this code:

self.tabBarController.selectedIndex = 1;

Where I get stuck is, how do I send data to this ViewController???

Upvotes: 2

Views: 759

Answers (1)

Levi
Levi

Reputation: 7343

You could either subclass your TabBarController, and add a property to it, or create a singleton (e.g. DataManager), to which all your ViewControllers will have access. You can pass your data to it.

Upvotes: 1

Related Questions