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:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
[pickerViewSelectionDefaults setInteger:row forKey:@"pickerViewSelectionKey"];
[pickerViewSelectionDefaults synchronize];
}
}
And...
- (void)viewWillAppear:(BOOL)animated {
NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
[pickerView selectRow:[pickerViewSelectionDefaults integerForKey:@"pickerViewSelectionKey"] inComponent:0 animated:YES];
}
Thanks!