我对此进行了研究,但只发现了如何将键盘切换为键盘。现在我有一个 UIPicker,它会在点击文本字段时出现。在 Picker 中有三个选项,第三个是自定义选项。What I want to happen is when custom is selected the UIPicker is replaced with a keyboard. 我猜这将通过该if (select == 2) { }
方法完成。我不需要一大堆代码,只需要替换 Picker 的方法。另外我想制作一个带有后退按钮的工具栏来返回选择器。我目前有一个带有 doneButton 的工具栏来释放选择器,但我需要在键盘出现时出现一个按钮,并且该按钮能够将键盘切换回我的选择器。
到目前为止,我的选择器、工具栏和文本字段是:
...
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *array = [[NSArray alloc] initWithObjects:@"...",@"...",@"Custom", nil];
self.PickerData = array;
...
UIToolbar *toolBar = [[UIToolbar alloc] init];
toolBar.barStyle = UIBarStyleBlackOpaque;
[toolBar sizeToFit];
...
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self
action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(releasePicker)];
Picker = [[UIPickerView alloc] init];
Picker.showsSelectionIndicator = YES;
Picker.delegate = self;
doneButton.image = [UIImage imageNamed:@"button.png"];
[toolBar setItems:@[flexSpace, doneButton] animated:YES];
self.habitField.inputAccessoryView = toolBar;
[self.habitField setEnabled: YES];
[self.habitField setInputView:Picker];
}
- (void)releasePicker {
[self.habitField resignFirstResponder];
}
...
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [PickerData count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.PickerData objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int select = row;
if (select == 0) {
...
}
if (select == 1) {
...
}
if (select == 2) {
...
}
}
@end