Is it possible to change the default InputView in MonoTouch? - iphone

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!

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

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

Related

how to open new view on touch even for uitextfield

I am just woundering if it is possible and if so how I could go about loading a new
view when the user touches a uitextfield?
What I am trying to do is load a new view where the user will use a picker to populate the UItextField instead of typing the word.
any help would be greatly appreciated
What you need here is the inputView property of UITextField. If you set this for a text field, then instead of the usual keyboard, the inputView object will pop up. I had created this example for a related problem which uses a UIPickerView as an inputView to a UITextField object. You can check it to see if it helps.

UIPicker in inappsettingskit

Using inappsettingskit, I'm searching for a way to display an uipickerview (with custom values) when clicking on a textfield cell (instead of a keyboard).
Is there any way to do so ?
Thanks for your help :)
Read the setting in you application and for showing picker view instead of standard keyboard use UITextField inputView property.
myTextField.inputView = myPickerView;
From Apple Documentation for inputView .
If the value in this property is nil,
the text field displays the standard
system keyboard when it becomes first
responder. Assigning a custom view to
this property causes that view to be
presented instead.

How to set the popup keyboard to only show certain keys?

How do you set the popup keyboard to only show certain keys when you type into a textfield? I know there are default keyboards but none seems suitable. Is there an alternative input option? Thanks.
Since iOS 3.2, you can change the keyboard :
cf.
Official documentation here
Discussion
The value of this property is nil.
Responder objects that require a
custom view to gather input from the
user should redeclare this property as
readwrite and use it to manage their
custom input view. When the receiver
subsequently becomes the first
responder, the responder
infrastructure presents the specified
input view automatically. Similarly,
when the view resigns its first
responder status, the responder
infrastructure automatically dismisses
the specified view.
This property is typically used to
replace the system-supplied keyboard
that is presented for UITextField and
UITextView objects.
Apple wont allow you to do any alterations to the keyboards..
What do you want to enter? Either create a custom keyboard, use pickers if possible or code it to not accepts certain keys..
Okay. I did'nt know you were allowed to change the keyboard now..
I usually use a picker. and have one of the segments just contain a "," the rest of the segments are 0-9..
or you could do something like this:
What is the best way to enter numeric values with decimal points?
But since its okay to change the keyboard now try this:
http://blog.devedup.com/index.php/2010/03/13/iphone-number-pad-with-a-decimal-point/

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).

Custom UIView with keyboard input?

I have a custom UILabel subclass for displaying currency values. I only want the user to be able to enter digits and let the view format those digits into a currency value -- like a cash register. This makes UITextField an inappropriate choice for this kind of input.
I've already overridden hitTest: so that the UILabel will return itself -- this is apparently a bug. Also, I've overridden both canBecomeFirstResponder and becomeFirstResponder to return YES. Neither of these methods are being called, though.
I only want to let the user type numbers and use the backspace key. I've implemented UITextInputTraits, but the keyboard does not appear. So, can this be done? And does if so, what am I missing?
I've done something like this. Subclass UITextField, make its text color clear, and stick a label on top of it to display the formatted version.
edit - actually, strictly speaking you shouldn't even need to subclass it. Just implement the delegate method (-textField:shouldChangeCharactersInRange:replacementString:), add the label to the UITextField, and format the label's text however you need to.
OK, I've answered my own question: a UILabel placed on top of the UITextView will also hide the insertion point, but can still become the first responder and get input.
Thanks!