views:

32

answers:

1

Hi,

I have an UIPickerView with 2 components. I save the user picker selection with NSUserDefaults. Both components have the save rows text.

For some reason, it saves only the last selected row and apply it on the other component, for example: If I select row 0 in component 0 and then select row 1 in component 1, and try to access them again it selects row 1 in both components instead of row 0 & row 1.

Here's my saving code:


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


    NSUserDefaults *pickerSelectionDefaults = [NSUserDefaults standardUserDefaults];

    [pickerSelectionDefaults setInteger:row forKey:@"leftComponentSelectionKey"];   
    [pickerSelectionDefaults setInteger:row forKey:@"rightComponentSelectionKey"];

    [pickerSelectionDefaults synchronize];

}

- (void)viewWillAppear:(BOOL)animated {

    NSUserDefaults *pickerSelectionDefaults = [NSUserDefaults standardUserDefaults];
    [enginesPicker selectRow:[pickerSelectionDefaults integerForKey:@"leftComponentSelectionKey"] inComponent:0 animated:YES];

    [enginesPicker selectRow:[pickerSelectionDefaults integerForKey:@"rightComponentSelectionKey"] inComponent:1 animated:YES];

}

Thanks!

A: 

I'm going to take a guess and say that you need a little more than just setting the value of the picker:component, and that little bit more is:

[enginesPicker reloadComponent:0];
[enginesPicker reloadComponent:1];

I think you can also use:

[enginesPicker reloadAllComponents];

Cheers!

(P.S., If this works remember to accept and mark it up.) (^_^)

Kevin Bomberry

related questions