Waitak Jong Waitak Jong - 9 months ago 29
iOS Question

How to change the variable of all tabs of the tabbarcontroller from first tab?

I have

@property NSString *memberid;

I will use it in all of it's

I want to update the
by one of it's
. so that other view controller can use the new value.

How can I update the


I am doing something like this in one of my project,

NSArray *tabArr = [self.tabBarController viewControllers];

UINavigationController *navController1 = [tabArr objectAtIndex:1];

DraftViewController *dvc = [navController1.viewControllers firstObject];

dvc.screenTitle = self.screenTitle;

UINavigationController *navController3 = [tabArr objectAtIndex:3];
SentViewController *svc = [navController3.viewControllers firstObject];

svc.screenTitle = self.screenTitle;

UINavigationController *navController2 = [tabArr objectAtIndex:2];
OutboxViewController *ovc = [navController2.viewControllers firstObject];

ovc.screenTitle = self.screenTitle;

I am doing that in my first tab (first viewcontroller of tabbarcontroller)

I have embed navigationcontroller to every viewcontroller (tabs). So, i get first nav controller and then get VC(tab).

If you don't have nav controller embed to your tab VC then [tabArr objectAtIndex:index] returns view controller directly.