How do I pass data from a tab bar controller to one of its tabs?

后端 未结 6 765
滥情空心
滥情空心 2021-02-02 09:21

I have a UITabBarController set up in storyboard. I want to pass a dictionary of data from the tab bar controller for use in the appropriate child tab, which is a standard UIVie

6条回答
  •  走了就别回头了
    2021-02-02 10:01

    If you got an UINavigationController as one of your UITabBarController view controllers, you can do the following:

    NSArray *viewControllers = [self.tabBarController viewControllers];
    UINavigationController *myNavController = (UINavigationController *)viewControllers[2];
    MyViewController *myController = [[myNavController childViewControllers] firstObject];
    // Remember to alloc/init objects first if the objects haven't been initialized already.
    [myController.whateverArray = [[NSArray alloc] initWithArray:@[@"Example1", @"Example2"]];
    [self.tabBarController setSelectedIndex:2];
    

提交回复
热议问题