I have a UITextField that uses a custom UIPickerView in its inputView to restrict the user to a few parameters that work similar to a drop-down list. When used with a hardware keyboard connected via Bluetooth, the hardware keyboard overrides (and hides) my inputView . However, the associated inputAccessoryView remains. When I press the keyboard button on my hardware keyboard (which usually displays the default on-screen keyboard for vanilla UITextField ), everything works as expected. (By this, I mean that my inputView is visible again.) In the previous version of iOS (i.e. 7 and below), the inputView always displayed when called.
I temporarily fixed the problem by setting the UITextField UIKeyboardType from UIKeyboardTypeDefault to UIKeyboardTypeTwitter , but this will only work when the hardware keyboard is not recognized by default for this particular UIKeyboardType . Code pickerTextField.keyboardType = UIKeyboardTypeTwitter; (see approximately 2/3 of the code path below). With further testing, this partial solution is not as useful as it seems.
How can I correctly display my inputView in all situations when using a hardware keyboard?
Corresponding 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 information . After checking a few other places, I confirmed that this is happening in at least one Apple product. (In the app / page "Create a New Apple ID" on iPhone 6 in 8.0.2. See "Date of Birth" for the month and day.)
ios ios8
Maple
source share