I have a form with multiple textfields.
The majority of these textfields, when clicked, produce the standard behaviour by displaying the keyboard in the expected way.
However when some of these textfields are clicked, I would like to override the standard behaviour by displaying either:
1) A datepicker, or
2) A Combobox
QUESTION 1:
How do I override the standard behaviour and display a datepicker/combobox instead of the default keyboard?
QUESTION 2:
I currently have a situation where there may be both keyboard and datepicker/combobox (keyboard on top of datepicker/combobox or vice versa) displayed on screen at the same time.
How do I prevent this from occuring, as there should only be one or the other (default keyboard, or datepicker/combobox) being displayed at any given time.
PS I have viewed other questions on this site which are similar but they dont seem to answer my quesions.
Any comments/suggestions appreciated...
Implement textfiled delegates and in the delegate method
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//Check the textfield for which you want to display date picker
if(textField == datePickerTextField)
{
[self showDatePicker];
return NO; //to disallow editing i.e it will not open keyboard
}
}
Fisrt You need create textfield. then its edit event blur that textfield and open your datepicker or combobox.
Thats method to hide keyboard & show datepicker in Titanium.
This can be achieved via trick.
To hide showing keyboard, set this property in text field.
enabled:false
And use text field click event to show date picker.
Related
I have a UIScrollView with 2 views, side by side, each of which covers the entire screen.
They are moved to visible bounds on user's action, only one covering the screen at a time. Both of these views have multiple UITextFields. Working with the simulator, I fill in a textField in the first view and when I press the Tab key, the firstResponder is assigned to a textField in the other view. I understand that on using the device, the user will not be able to do that. But what if the user uses a bluetooth keyboard, or similar accessory? I do not want a textField, that is currently not visible to become firstResponder. Can this be done?
EDIT: I just remembered the canBecomeFirstResponder method. But how do I determine which textField is about to becomeFirstResponder?
It sounds like the problem isn't that they shouldn't be able to tab between the two text fields, but instead that they shouldn't be able to edit a text field that isn't visible, and they should be able to tab between them if they are both visible at the same time.
Instead of restricting tab, I would implement the UITextField delegate method -textFieldShouldBeginEditing:, which allows you to return a boolean whether or not that text field should become the first responder.
Something such as:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
// Only edit if the text field is visible
return !textField.isHidden;
}
You may need to adjust this code to fit your 'is visible' status of the text field.
I am working on implementing something in my iOS app that I see in mobile websites all the time. I would like to have a TextBox or TextField of some kind that shows what value is currently selected. When clicked, it will present a UIPickerView with a list of possible choices. Upon selection, the UIPickerView will disappear, and the TextBox or TextField would get updated with the selection the user made. Can someone point me in a good direction for doing this?
You can save indexPath value in a string and show it on textfield like: [textField setText:NSString];
I have a table view containing 10 cells and each cell has a text field. Till textfield 5, I want the user to enter some value using keyboard. On text field 6, I want the user to select values from a list (showing picker view).
What is happening is when I click on field 5 (showing keyboard), entered some value and then hit return button (on keyboard), the keyboard goes down and then, I click on text field 6 (showing picker), the picker is shown (no keyboard appears here).
BUT if I dont hit return button of keyboard (on field 5) and directly click on field 6 (picker), then my picker appears with the keyboard at the top, that is, keyboard doesn't goes down and picker appears behind the keyboard. Here, when I click on return of keyboard, then also keyboard doesn't goes down. To make the keyboard go down, I need to click on any text field (showing keyboard) and then hit return.
Has anybody faced this strange problem?? Please help me out.
you have to set the tag of each textfield and set the delegate and then put this delegate method like this,
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
If (textField.tag == 6)
{
[textField resignFirstResponder];
}
return YES;
}
Enjoy!
Dont add the picker as a subview manually. Set it as the inputView of the text field (on cellForRowAtIndexPath) and the OS will take care of showing and hiding for you.
I need to get the cursor in textfiled but on the textfileddidbeginEditing i have to open the picker view for selection , so for that reason i need to resignFirtsresponder to the textfield ,inorder that picker view is visible .But by doing this the cursor gets disabled as i open the picker (and the keyboard gets hide by resignFirst responder).I want to show the cursor as because when user cliks on partilcuar textfield so by that cursor he can track on which textfield he is making the selection.
Hope i am clear with my question.
if you want the picker instead of keyboard, set the text fields inputView as the picker... so when you tap the text field the picker will pop up like keyboard and the textfield will show the cursor too.. no need to dismiss the keyboard and then show the picker..
If I understand your problem right, this is just an usability problem. I think you can solve this if you just add some other mechanism for showing the user which textfield is in editing-mode.
For example add an text-color to the TextField. If the user disable the UIPickerView set the text-color back to the normal state.
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).