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.
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 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.
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 the following code...
- (void)textFieldDidBeginEditing:(UITextField *)textField {
//some code here...
NSInteger theTag = textField.tag; //I set the tag to 5 in IB
if (theTag == 5) {
//self.showDatePicker;
[textField resignFirstResponder];
}
}
The problem is, the keyboard never disappears. Another thing to note is that I have some other methods that move the view up and down based on the position of the textfield selected. Maybe that's messing up my Responder, but I just don't understand why the keyboard won't go away.
Also, I might just be doing this all wrong. I want this textField, when pressed, to hide the keyboard and show a date picker. Should this be in a different method?
If you're targeting iOS 3.2+, I'd suggest looking into UITextField's inputView property. You can assign a custom view (i.e. a data picker) to be displayed when the text field becomes the first responder instead of the keyboard.
I have a UIViewController that has two text fields, inputA and inputB. inputA works like a normal text field, click it and the keyboard shows up and you can type. But inputB triggers another view (think of it as a button). This second view, MyView, has a custom popup view which is animated to appear with the keyboard. MyView's popup is initially with the alpha to 0 and I have set notifications for when the keyboard shows up to have the popup's view alpha to be set to 1.
This works great, but I have a "bug" where when the keyboard is currently showing because the user tapped inputA first, then they tap inputB, it fires the MyView but because the keyboard is already showing the notification isn't sent to change the popup alpha to 1.
So the question: what is the clean way to work around this issue? I want the view to appear along with the keyboard, but if it is already there, it should just be sent.
Is there a way to test if the keyboard is already showing? I want to do this without setting a bool value every time the keyboard is shown/hide in those two views.
try the following
if ([inputA isFirstResponder] || [inputB isFirstResponder]){
//keyboard is displayed
}else{
//keyboard is not displayed
}