Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard pass data from view controller to tab bar with segue

I have one page(say X) before tab bar controller that use model segue to open tab bar controller. Also first screen of tab bar controller is same with X.

I want to pass data from X to tab bar controller's first page.

Shortly, I want to pass data from view controller to tab bar controller page with storyboard segue. Is there any method for this ?

Here is the solution ;

    locationsHome* vc = [[locationsHome alloc] init];
    UITabBarController* tbc = [segue destinationViewController];
    vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
like image 998
SiberKorsan Avatar asked Dec 21 '22 15:12

SiberKorsan


1 Answers

This is how I solved my problem. You can pass data from ViewController to TabBarController with this method.

Use this code within prepareForSegue method

locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];

Like this:

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

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

        locationsHome* vc = [[locationsHome alloc] init];
        UITabBarController* tbc = [segue destinationViewController];
        vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];

        etc...

    }
}
like image 184
SiberKorsan Avatar answered May 07 '23 18:05

SiberKorsan