tags:

views:

362

answers:

1

I have a tab bar app. One of the controllers is a "preference page". What I am trying to do accomplish is access the uiswitch ivar that is on the "preference page" controller from the app delegate's applicationWillTerminate method, however I am only getting the default IUSwitch value.

Here is the code:

- (void)applicationWillTerminate:(UIApplication *)application {
  SettingsController *settings = [[SettingsController alloc] initWithNibName:@"SettingsView" bundle:nil]];
  NSLog(@"settings preference value: %d", [settings isOn]);
}
A: 

This wont work because your are essentially creating another instance new of SettingsController which of course will not include a reference to the settings ivar in the original SettingsController. What you need to do is save a reference to the original SettingdController somewhere, either in the app delegate or in a singleton object.

Here's a good blog on wether to use the app delegate or singleton method to pass around global references. I would personally use the singleton method.

ennuikiller
you are exactly right. (forgot to mention that I recognized that my current methodology was flawed). Is there a straight forward way to accomplish what I am doing or should I go down another path?
Cory Wiles
see the link I provided in the answer for ways of dealing with this.
ennuikiller