在TabBarViewController的Tabs之间传递数据

我有一个基于UITabBarController的应用程序,我想从一个视图传递数据到另一个。 我正在做故事板,我只是做一些testing,然后把它带到主应用程序。

我现在只是用NSString试试这个。

当我使用这个代码使用模态转换时,我能够将数据传递给有问题的VC:

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]; 

现在,这推动了VC,并按照我的意愿传递,而不是推高VC,我希望它被推到另一个标签栏。

现在我可以用下面的代码来popup所需的TabBar:

 self.tabBarController.selectedIndex = 1; 

我卡住的地方是,如何发送数据到这个ViewController?

你可以TabBarController你的TabBarController ,并为它添加一个属性,或者创build一个单例(例如DataManager),你所有的ViewControllers都可以访问它。 您可以将数据传递给它。