在从选取器中选择行时,使用两个 int iVar 来保存选取器的索引。
int a,b;
BOOL isArray1IsUsedInPicker;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(isArray1IsUsedInPicker)
a=row;
else
b=row;
}
并且当您根据数组重新加载选择器时,相应地调整 BOOL 变量
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
// your code ---
// set isArray1IsUsedInPicker = YES; if going to use array1 else set NO
[picker reloadComponent];
if(isArray1IsUsedInPicker)
[picker selectRow:a inComponent:0 animated:NO];
else
[picker selectRow:b inComponent:0 animated:NO];
}