Steaphann
Steaphann

Reputation: 2777

set value for first tab in tabbar after segue

I have the following situation. enter image description here

Like you see I have a segue that goes to the tabbarController. But I need to set an id in de VC that is pointed on the screen. Have you guys any idea how I can achieve this.

Normally you would use this code.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"showTab"]) {
        [segue.destinationViewController setPersonId:personobject.cu_id];
    }
}

But this goes to my tabbarController and not to my FirstTabController. Any help?

Kind regards

Upvotes: 0

Views: 228

Answers (2)

Steaphann
Steaphann

Reputation: 2777

Oké,

I fixed my problem by just saving my personId into NSUserDefaults at the following way.

 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
                             [prefs setInteger:[personObject.cu_id intValue] forKey:@"personId"];
                             [prefs synchronize];

Now I can get access to it in every VC by calling the following.

 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    _personId = [NSNumber numberWithInt:[prefs integerForKey:@"personId"]];

Upvotes: 0

Joris Kluivers
Joris Kluivers

Reputation: 12081

Your destination view controller is a UITabBarController. You'll have to get an instance from that tab controller to the controller in the first tab.

UITabBarController *tabController = (UITabBarController *) segue.destinationViewController;
FirstTabController *firstController = [tabController.viewControllers objectAtIndex:0];

[firstController setPersonId:personobject.cu_id];

Upvotes: 1

Related Questions