سؤال

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