I have researched this, but found only how to switch a keyboard for a keyboard. Right now I have a UIPicker and that appears when a textfield is tapped. In the Picker their are three options, and the third is custom. What I want to happen is when custom is selected the UIPicker is replaced with a keyboard. Im guessing this would be done with the if (select == 2) { }
method. I don't need a whole bunch of code, just the method for replacing the Picker. Also I would want to make a toolBar with a back button to get back to the picker. I currently have a toolbar with a doneButton to release the picker, but I would need to make a button appear when the keyboard appears and the button be able to switch the keyboard back to my Picker.
So far my picker, toolabr and textfield are :
...
- (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
if (select == 2) {
[self.habitField resignFirstResponder];
[self.habitField setInputView:nil];
[self.habitField becomeFirstResponder];
}
This is basically hiding the UIPickerView then removing it and then popping up the keyboard.
If you want the UIPicker buck up use this code:
[self.habitField resignFirstResponder];
[self.habitField setInputView:PickerData];
[self.habitField becomeFirstResponder];