iphone - 如何每次选择/设置选取器 View 中的选定行作为默认选定行

标签 iphone objective-c datepicker uipickerview didselectrowatindexpath

我有一个选择器 View

[picker selectRow:3 inComponent:0 animated:YES];

当我在 View 中编写此代码时,确实加载了,

该方法用于将第3行设置为选择器中的默认行。

但我希望我选择的行下次设置为默认行。

要做什么?提前致谢...

最佳答案

尝试这样

NSUserDefaults *usrDefaults = [NSUserDefaults standardUserDefaults]; 

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

    [usrDefaults setInteger:row forKey:@"Index"];
}

[pickerView selectRow:[[NSUserDefaults standardUserDefaults]integerForKey:@"Index"] inComponent:0 animated:NO];

关于iphone - 如何每次选择/设置选取器 View 中的选定行作为默认选定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9600470/

相关文章:

iphone - 将类别方法添加到 NSObject,但收到警告,因为当我调用它时它不在 <NSObject> 协议(protocol)中

jQuery Datepicker 与之前提交的输入字段重叠

android - 在android中调整DatePicker的大小

java - GWT 函数在 DatePicker 能够返回所选日期之前完成,如何延迟直到返回日期?

iphone - 如何以编程方式通过短信将图片作为附件发送?

iphone - 我可以将 NSURLCredentialStorage 与数据保护结合使用吗?

iOS Storyboard 更改初始 View

ios - didReceiveRemoteNotification :fetchCompletionHandler: but the completion handler was never called

ios - 如何在 objective-c 中调用的方法中传递五个值

ios - 滚动时更新 UITableViewCell