我有一个picker视图,其中有一个数字列表可供选择。我希望能够在特定的行上初始化控件。例如,如果用户指定10作为默认值,则在首次初始化控件时,控件应自动定位在该行。
提前谢谢。
发布于 2009-10-29 03:48:10
调用selectRow:inComponent:animated:
并将希望选择的行的索引传递给它。
这段代码会导致UIPickerView
在0上停留之前,将其数字从0旋转到60。
- (void)viewDidAppear:(BOOL)animated {
[thePicker selectRow:60 inComponent:0 animated:YES];
[thePicker reloadComponent:0];
[thePicker selectRow:60 inComponent:1 animated:YES];
[thePicker reloadComponent:1];
[thePicker selectRow:0 inComponent:0 animated:YES];
[thePicker reloadComponent:0];
[thePicker selectRow:0 inComponent:1 animated:YES];
[thePicker reloadComponent:1];
}
在您的示例中,要显示第10行,您可以调用如下代码:
[thePicker selectRow:10 inComponent:0 animated:YES];
发布于 2015-11-16 07:11:35
您可以做的不是选择行,而是让选择器视图找到您想要的值。方法是创建一个循环来在数组中找到它并选择它:
- (void)viewDidAppear:(BOOL)animated{
int i = 0;
for(NSString* number in arrayName)
{
if ([stringValue isEqualToString:number]){
[pickerViewName selectRow:i inComponent:0 animated:YES ];
}
i++;
}
}
发布于 2015-12-11 02:39:55
如果您在UIPickerView
中使用UITextField
[self.text_field setInputView:self.picker];
然后使用以下命令:
self.text_field.text = [_myarray objectAtIndex:10];
https://stackoverflow.com/questions/1639452
复制相似问题