I have a UISwitch in my app along with one in my settings bundle with the same functionality. The UISwitch in my app however is not saving its settings properly. Can anyone see anything wrong with the code?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Set the application defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"No" forKey:@"isKgs"];
[defaults registerDefaults:appDefaults];
[defaults synchronize];
}
- (void)switchChanged
{
[[NSUserDefaults standardUserDefaults] setBool:unitSwitch.selected forKey:@"isKgs"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"SwitchGhanged:");
}
-(void)cellForRowAtIndexPath
{
[unitSwitch addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventValueChanged];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isKgs"])
{
[unitSwitch setOn:YES animated:NO];
}
}
And here is the settings bundle

Use the
onproperty for setting.