我的pickerview 有问题,单击文本字段会显示一个空的uipickerview。我有 3 个文本字段,通过单击每个文本字段,每个文本字段都会有不同的数组。这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
tbMode.inputView = pickerView;
tbWalkDist.inputView = pickerView;
tbRouteOpt.inputView = pickerView;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
-(void)textFieldDidBeginEditing:(UITextField*)textField;
{
modeArray = [[NSMutableArray alloc] init];
if(textField.tag==1){
[modeArray addObject:@" A "];
[modeArray addObject:@" B "];
pickerView.hidden = NO;
}
else{
if(textField.tag==2){
[modeArray addObject:@" 300 "];
[modeArray addObject:@" 400 "];
[modeArray addObject:@" 500 "];
pickerView.hidden = NO;
}
else{
if(textField.tag==3){
[modeArray addObject:@" cheapest "];
[modeArray addObject:@" fastest "];
pickerView.hidden = NO;
}
else{
pickerView.hidden=YES;
}
}
}
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
tbMode.text = [modeArray objectAtIndex:row];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
return [modeArray count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
return [modeArray objectAtIndex:row];
}
请帮忙!我哪里做错了?是否有可能-(void)textFieldDidBeginEditing:(UITextField*)textField;
不调用此方法?谢谢
编辑*我错过了这 3 行,它们是用于调用该方法的每个文本字段viewDidLoad
tbMode.delegate = self;
tbWalkDist.delegate = self;
tbRouteOpt.delegate = self;
但我仍然得到一个空的选择器视图。我如何将这些添加NSMutableArray
到选择器视图中 *添加[pickerView reloadAllComponents];
到选择器中将显示值:)