8

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.)

Maple
  • 741
  • 13
  • 28
  • I have reason to suspect that this is the same cause for interference from installed custom keyboards such as Swype. See http://stackoverflow.com/q/26020956/650365 – Maple Sep 30 '14 at 19:09
  • I would also like to find a solution for this. Custom input views should show up regardless of the presence of a hardware keyboard. – albertamg Oct 14 '14 at 15:50

1 Answers1

0

The issue was fixed by Apple in the iOS 8.1 update.

Maple
  • 741
  • 13
  • 28
  • Not fixed. It's a bug that iOS doesn't hide the inputView in 8.1. It should be hidden just like in 8.0 and 8.0.1 – Paul Bruneau Nov 17 '14 at 04:51
  • @EthicalPaul There's a bit of a conflict of usage here. On one side, an inputView that functions as a keyboard ought to be overridden when a hardware keyboard is attached. On the other, inputViews that do not function as keyboards (e.g. Apple's own Month pickerViews in various apps) should not be hidden. Until Input Engineering adds in a flag to allow the developer to indicate which is preferred, the 8.1 fix/bug at least allows all functionality to be accessed, with a trade-off of a little annoyance on group 1's usage. (TL;DR - Not all inputViews are equivalent to keyboards, but some are.) – Maple Nov 17 '14 at 20:55