Attempting to transfer data between tab bar controllers

I am trying to transfer some data between my views in a tab bar. my first view is to load and manipulate data from my model class. But when I click the second or third tab in my tab bar controller, the data is not transferred. This is how I try to convey it.

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

if (tabBarController.selectedIndex == 1){
HashTagTableViewController *hash [[HashTagTableViewController alloc]init];
    hash.userArray = feed.userArray;
}else if (tabBarController.selectedIndex == 2){
    PhotoTagTableViewController *photo = [[PhotoTagTableViewController alloc]init;
    photo.userArray = feed.userArray;

}

}

feed is the name of the instance of my model class that I created in the current controller. I am trying to avoid creating multiple instances of the model class as it must make multiple API calls. All I am trying to do is pass on to feed.userArrayother views that need to be manipulated differently.

+4
source share
2 answers

. UITabBarController . :

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    if (tabBarController.selectedIndex == 1){
        HashTagTableViewController *hash = (HashTagTableViewController *) viewController;
        hash.userArray = feed.userArray;
    }else if (tabBarController.selectedIndex == 2){
        PhotoTagTableViewController *photo = (PhotoTagTableViewController *)viewController;
        photo.userArray = feed.userArray;
    }
}
+3

ViewController. ViewBontroller TabBarController. . .

:

, / . . xcode.

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if([viewController isKindOfClass: [HashTagTableViewController class]]) 
    {   
        HashTagTableViewController *hash = (HashTagTableViewController) viewController;
        hash.userArray = feed.userArray;
    }
    else if([viewController isKindOfClass: [PhotoTagTableViewController class]]) 
    {
        PhotoTagTableViewController *photo = (PhotoTagTableViewController) viewController;
        photo.userArray = feed.userArray;
    }       
}
0

All Articles