I have a UITextField
that uses a custom UIPickerView
in its inputView
to restrict the user to a few options, functioning analogous to a dropdown list. When used with a hardware keyboard connected via bluetooth, the hardware keyboard overrides (and hides) my inputView
. The associated inputAccessoryView
remains, however. When press the "keyboard" button on my hardware keyboard (which would normally display the default on-screen keyboard for a vanilla UITextField
), everything works as expected. (By which I mean my inputView
is visible again.) In prior version of iOS (i.e. 7 and below), the inputView
was always visible when called.
I have temporarily solved the problem by setting the UITextField
's UIKeyboardType
from UIKeyboardTypeDefault
to UIKeyboardTypeTwitter
, but this will only work while the hardware keyboard is not recognized as the default for that particular UIKeyboardType
. Code is pickerTextField.keyboardType = UIKeyboardTypeTwitter;
(See about 2/3 of the way into the code below.) Upon further testing, this partial solution isn't nearly as useful as it seems.
How can I correctly display my inputView
in all situations while using a hardware keyboard?
Relevant code snippet:
-(int)setUpPickerWheelAtXLoc:(int)xLoc andYLoc:(int)yLoc {
int qwidth = width - (xLoc - FORMBORDERLEFT);
// Set up inputView (pickerView) to replace the keyboard
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, height)];
self.pickerView.delegate = self;
self.pickerView.dataSource = self;
self.pickerTextField = [[UITextField alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, 32)];
self.pickerTextField.delegate = self;
pickerTextField.borderStyle = UITextBorderStyleRoundedRect;
pickerTextField.layer.borderWidth = 0.3f;
pickerTextField.layer.borderColor = [[UIColor blackColor] CGColor];
pickerTextField.textColor = [UIColor blackColor];
pickerTextField.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
pickerTextField.placeholder = @"Tap to choose from list...";
// Add pickerView as inputView
pickerTextField.inputView = self.pickerView;
pickerTextField.keyboardType = UIKeyboardTypeTwitter; // Suggested temporary solution
// Setup inputAccessoryView (Done button)
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneButton addTarget:self action:@selector(pickerDoneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
doneButton.titleLabel.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
doneButton.frame = CGRectMake(0,0,100,44);
[doneButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
doneButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
doneButton.backgroundColor = [UIColor lightGrayColor];
pickerTextField.inputAccessoryView = doneButton;
return xLoc + qwidth;
}
Additional Info: After checking a few other places, I have confirmed that this is happening in at least one Apple product as well. (In the "Create New Apple ID" app/page on an iPhone 6 in 8.0.2. See the Date of Birth pickerviews for Month and Day.)
The issue was fixed by Apple in the iOS 8.1 update.