0
votes

Hi I added a prepare for segue code in order to transfer information, however I'm getting an error.

I have a tab bar controller. It has 4 tabs. Each tab has a navigation controller, and a VC as a root view controller.

from tab 1-->nav controller-->VC 1 I need to take a value to tab2-->nav controller --->VC1

(also is the segue connected to the nav controller at tab 2, or the root view at tab 2) Thank you in advance

error:customizableViewControllers]: unrecognized selector sent to instance 0xf19bd60 (but I am going to tab 2 (index 1))? where is my error?

    if ([segue.identifier isEqualToString:@"ResultsSegue"])

        {
//the root VC at tab 2
            ResultsIndexViewController*controller=[[ResultsIndexViewController alloc]init];

            UITabBarController *tabController = [segue destinationViewController];
            controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here
            controller.resultsArray=[NSMutableArray arrayWithArray:_matchedResultsArray];

        }
    }
1
also, do I need delegates for this?William Falcon
Your error basically means, that tabbarcontroller is not a UITabBarController. Are sure, that [segue destinationViewController] returns a UITabBarController? Is that, how the segue is configured?SAE
the segue goes to a navigation controller, should it be linked to tabbar controller?William Falcon
O.k. - that explains the error: you think, that it's a tabbarcontroller, but it actually is an navigation controller. customizableViewControllers is a method for tabbarcontroller; nav controllers don't understand this. If it should be linked to a tabbar controller depends only on what you want to achieve. Nav controller is something completely different than a tab controller. Whatever; the code must reflect what is in your storyboard. Either both nav or both tabbar.SAE
so I have a tabcontroller (bottom). It has four tabs. Each tab was created by having a UINav controller with a root view. the nav controllers were connected (dragged) to tab bar controller.William Falcon

1 Answers

1
votes

This part of your code

 [1]   UITabBarController *tabController = [segue destinationViewController];
 [2]    controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here

Is full of misconceptions.

In [1] you are assigning a destinationViewController (type UIViewController) to an object of type UITabBarController. This is compiler-legal (UITabBarController inherits from UIViewController so they are both of type UIViewController) but it doesn't reflect really what is going on. Your segue will be to the UIViewController or it's UINavigationController.

So in line [2] when you try to use your tabController as a tab bar controller, it crashes (because it isn't one).

You need to redesign your project... forget the Segue, and use the tab bar controller. Something like...

- (IBAction)moveToTab2:(id)sender {
    ResultsViewController* resultsVC = (ResultsViewController*)
                [[self.tabBarController viewControllers] objectAtIndex:1];
    resultsVC.resultsArray=
                [NSMutableArray arrayWithArray:_matchedResultsArray];
    [self.tabBarController setSelectedViewController:resultsVC;
}