Question

I would like to display a different view than the standard keyboard (a picker control, or a date picker, for example) when a text field becomes first responder (i.e. gets focus). This would be really nice, because currently I'm pushing a custom view which contains my picker control onto the navigation stack where the user chooses an option, and then hits an OK or Cancel button.

According to the documentation for UITextField.InputView:

Assigning a custom view to this property causes that view to be presented instead.

But, It's read only!!!

Is there a workaround for this? Do I need to implement a custom UITextField control and somehow override the InputView property? Do I need to call some kind of native function? I'd really love not to have to do either of those things... but if I have to, so be it. Thanks in advance!

Was it helpful?

Solution

The documentation is slightly out of date. There is a setter since MonoTouch 3.2.0.

OTHER TIPS

Kevin's answer will work for UIKeyboardType keyboards but as far as I'm aware (I could be wrong) you can't present a custom keyboard this way.

The only way I know how to present a custom keyboard is to override the InputView for the UIViewController you wish to present the input view.

UIView keyboardView;

public override UIView InputAccessoryView {
   get 
   {
       // create the view as you'd like here
       return keyboardView;
   }
}

Wire up the UITextField to handle the appropriate editing event and in the event handler select the KeyboardType you want. If you don't need to dynamically set it then you can just set the property when you create the text field.

UITextField tf;
...
tf.KeyboardType = UIKeyboardType.PhonePad; // whatever kb you want
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top