ios - 在 TabBarViewController 的选项卡之间传递数据

标签 ios uitabbarcontroller storyboard

我有一个基于 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/

相关文章:

ios - 将 presentModalViewController 与 Storyboard一起使用

objective-c - Push segue 在加载 View 之前短暂显示空白屏幕

ios - NSlog 不打印新行\r\n

ios - 如何在调用fetch之前验证NSPredicate

ios - 在未实例化的 View Controller 上设置角标(Badge)值的正确方法?

iphone - UITabBarItem 标题不显示

ios - Storyboard仅以 XML 格式显示

ios - swift : One Navigation bar item

ios - 导航 Controller 无法正常工作

ios - UITabbarController selectedIndex 和 selectedViewController 不起作用