如何在使用presentViewController和UITabbarController时传递数据
问题描述:
我是ios的新手。我试着用UITabbarController工作,当我尝试从ViewController(这个ViewController不是Tabbar中的一个项目)传递数据到Tabbar中的其他ViewController时,我遇到了一些问题。在这种情况下,当我点击按钮登录按钮时,会出现“欢迎购物”并且登录表单中的用户名将在“欢迎购物”中进入标签。 如何在使用presentViewController和UITabbarController时传递数据
我用下面的代码,使“开山鼻祖店”控制器出现:
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];