SiberKorsan SiberKorsan - 6 months ago 16
iOS Question

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];

Answer

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...

    }
}