0
votes

Hi am new to iphone developing, am doing my projects using storyboards, in my project i have login viewController if login success it will go to tabbarcontroller. In the tabbarController it has three viewControllers. between tabbarController and three view controllers i have an navigation controller.now the problem is i have to pass data from loginviewController to tabBarcontroller to navigationController . I dont know how to do it pls help me.. Thanks in advance i passed data from login controller to tabbarcontroller using this code

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    NSString * segueIdentifier = [segue identifier];
    if([segueIdentifier isEqualToString:@"dashboard"]){

        EventdashViewController *dc = [[EventdashViewController alloc] init];
        FeedDashViewController *fc = [[FeedDashViewController alloc]init];
        NewsDashViewController *nc = [[NewsDashViewController alloc]init];
        UITabBarController* tbc = [segue destinationViewController];
        dc = (EventdashViewController *)[[tbc customizableViewControllers] objectAtIndex:0];
        dc.memberid = userid1;
        NSLog(@"%d",dc.memberid);
        fc = (FeedDashViewController *) [[tbc customizableViewControllers]objectAtIndex:1];
        fc.memberid=userid1;
        NSLog(@"%d",fc.memberid);
        nc = (NewsDashViewController *)[[tbc customizableViewControllers]objectAtIndex:2];
        nc.memberid = userid1;
        NSLog(@"%d",nc.memberid);
    }
}

How to pass data from viewcontroller to tabbarcontroller to navigationcontroller?

1
What do you mean by "between tabbarController and three view controllers i have an navigation controller" ?? - Dunes Buggy
in tabbarcontroller i have three view controllers eventviewcontroller,feedbackviewcontroller and newsletterviewcontroller in storyboard the flow will be like loginview to tabbarcontroller then three navigation controllers for three viewcontrollers.. hope u understood - user2728139
Just give a storyboard id of TabbarController . and use it to segue or pass data .. ETC - Kumar KL
Okay. Then you will need to define these navigation controllers custom. I mean custom classes. You can iterate through tabbarcontroler's child controllers (your three navigation controllers), typecast your child controllers in this loop to the navigation controller class (you custom class). and then set the values inside that custom controller in the similar fashion you are doing in your code i.e. 'dc.memberid = userid1;'. If you dint understand any point, Let me know, I will try to explain. - Dunes Buggy

1 Answers

0
votes

First, it looks like what you're trying to do is pass data to the root view controllers of the navigation controllers (dc,fc, and nc), not the navigation controllers, which is what you should be doing. The problem is, that the customizableViewControllers is going to return the navigation controllers, not their root view controllers. Also, the three lines you have with alloc init are wrong, and useless anyway since you redefine what dc, fc, and nc are a couple of lines down -- if you've set this all up in the storyboard, the tab bar controller's content controllers are all instantiated when the tab bar controller is. What you should have is this:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    NSString * segueIdentifier = [segue identifier];
    if([segueIdentifier isEqualToString:@"dashboard"]){

        UITabBarController* tbc = [segue destinationViewController];
        dc = (EventdashViewController *)[(UINavigationController *)tbc.viewControllers[0] topViewController];
        dc.memberid = userid1;
        NSLog(@"%d",dc.memberid);
        fc = (FeedDashViewController *) [(UINavigationController *)tbc.viewControllers[1] topViewController];
        fc.memberid=userid1;
        NSLog(@"%d",fc.memberid);
        nc = (NewsDashViewController *)[(UINavigationController *)tbc.viewControllers[2] topViewController];
        nc.memberid = userid1;
        NSLog(@"%d",nc.memberid);
    }
}