我有一个基于 UITabBarController 的应用程序,我想将数据从一个 View 传递到另一个 View 。我在 Storyboard 中执行此操作,我只是在将其引入主应用程序之前进行一些测试。
我现在只是在尝试使用 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,而是被推到另一个标签栏。
现在我可以使用以下代码轻弹到所需的 TabBar:
self.tabBarController.selectedIndex = 1;
我卡住的地方是,我如何向这个 ViewController 发送数据???
最佳答案
您可以将您的 TabBarController
子类化,并向其添加一个属性,或者创建一个单例(例如 DataManager),您的所有 ViewControllers
都可以访问它。您可以将数据传递给它。
关于ios - 在 TabBarViewController 的选项卡之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14130076/