我是ios的新手。我尝试使用 UITabbarController,但当我尝试将数据从 ViewController(此 ViewController 不是 Tabbar 中的项目)传递到另一个 ViewController 时,我遇到了一些问题,该 ViewController 是 Tabbar 中的项目。在这种情况下,当我单击按钮登录时,我希望出现“欢迎光临购物”,并且登录表单中的用户名将传递到“欢迎光临购物”的标签中。
我使用下面的代码使“欢迎购物” Controller 出现:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabbarController= [storyboard instantiateViewControllerWithIdentifier: @"tabbarID"];
[self presentViewController: tabbarController animated: YES completion: nil];
所以对我将用户名(在 LoginController 中)传递到标签(WelcomeToShopController)有什么想法吗?
最佳答案
我研究后解决了我的问题:)。因为我使用了 tabbar 和 navigationController,所以我应该实例化 tabbar -> NavigationController -> ViewController。就我而言,下面的代码将完美运行。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabbarController= [storyboard instantiateViewControllerWithIdentifier: @"tabbarID"];
UINavigationController *nav = (UINavigationController *)[tabbarController.viewControllers firstObject];
HistoryOrderingController *historyOderingVC = (HistoryOrderingController *)[[nav viewControllers] firstObject];
historyOderingVC.user = self.user;
[self presentViewController: tabbarController animated: YES completion: nil];
关于ios - 将 presentViewController 与 UITabbarController 一起使用时如何传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38555935/