我是 Objective-C 的新手,我需要在触摸特定文本字段时创建一个 UIPickerView,该文本字段将填充 NSMutableArray 的项目。我已经实现了这段代码,但看不到添加的 pickerView。我仍然可以看到键盘触摸文本字段时弹出...我哪里错了..???
- (BOOL)textFieldDidBeginEditing:(UITextField *)textField {
if( textField == txtstate)
{
[txtstate resignFirstResponder];
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[self.view addSubview:pickerView];
}
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[pickerView selectRow:1 inComponent:0 animated:NO];
txtstate.text= [[arr objectAtIndex:row] valueForKey:@"Code"];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
return [arr count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
return [arr objectAtIndex:row];
}
我的数组看起来像这样:
(
{
Code = Wisconsin;
Id = "6215b339-2959-4a3d-9430-f5bddb0a4eb9";
},
{
Code = Wyoming;
Id = "7972f963-9b3b-4ba6-a30c-d68bb9f59145";
}
)
任何帮助,将不胜感激...