I have a UILabel that display 3 options which is walk, run, and swim. I have a corresponding picker view that displays these 3 options for users to choose when the users tap the UILabel. The default option for the UILabel is depend on what the users choose last time. I want the picker view to show the correct option when it is showed first time.

it seems there is no delegate method for picker view to do that.

有帮助吗?

解决方案

The default option for the UILabel is depend on what the users choose last time.

Then, you need to save the value within the App by using the NSUserDefaults.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    [[NSUserDefaults StandardDefaults] setObject:[NSNumber numberWithInt:row] objectForkey:@"selcetdRow"]
}

in the ViewDidLoad , just call this

 [picker selectRow:[[NSUserDefaults StandardDefaults] objectForkey:@"selcetdRow"]intValue] inComponent:0 animated:YES];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top