Passing data between the Tabs of a TabBarViewController

一笑奈何 提交于 2019-12-11 03:46:09

问题


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???


回答1:


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.



来源:https://stackoverflow.com/questions/14130076/passing-data-between-the-tabs-of-a-tabbarviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!