Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

guydor

macrumors member
Original poster
Mar 10, 2009
67
0
Hi,

I have an UIPickerView with 2 components. I would like to save the user's selection and to apply it next time the pickerView is shown again.

Here's my code:

Code:
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
    [pickerViewSelectionDefaults setInteger:row forKey:@"pickerViewSelectionKey"];
    [pickerViewSelectionDefaults synchronize];

}

}

And...

Code:
- (void)viewWillAppear:(BOOL)animated { 

    NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
    [pickerView selectRow:[pickerViewSelectionDefaults integerForKey:@"pickerViewSelectionKey"] inComponent:0 animated:YES];

}

The problem is that this NSUserDefaults settings don't save the UIPickerView selections.
My pickerView has 2 components.

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.