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.
Related
I can't seem to find how I could replace the keyboard when I tap a textfield in the following context:
I have a view controller with a tableview dragged into it with one prototype cell, and in that cell I have 4 textfields. As for my swift files, I have one for the table view (view controller) and one for the cell itself.
I was able to replace the keyboard with a datepicker for one textfield, but do not know how to proceed for a picker view...
Thank you in advance for any help/advice given! Please let me know if you need more detail.
Cheers,
Laroms
As far as I understand, you are asking to change the input type of the UITextField.
You can make use of inputView property of the UITextField. Set the inputView for the required textField as UIPickerView. It'll automatically change the input type.
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.
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
In my project (my first one) I try to assign a text to a textfield created in the Interface Builder.
[date setText:#"2010"];
I also tried using
date.text = #"2010"
I have created the Outlet and don't get any error... the text just doesn't show up.
Just in case it matters...
I prevent the keyboard from showing up and display a calendar instead (works).
Any idea what could be wrong?
Could it be a problem that I'm using delegate methods on the textFields to prevent displaying the keyboard?
If you don't want to edit text using a keyboard, then what is the use of UITextField?
Instead of using UITextField you can use a UILabel (as a global variable) to show the text and use a custom UIButton without a title and use its action for showing the calendar view. You can change the text of the label whenever you want in that class like viewWillAppear or viewDidAppear.
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).