UITableViewCell and resignFirstResponder - iphone

I have a UITableView containing in each cell a UITextField. When the user clicks on the UITextField, as expected, the keyboard will popup.
I have implemented in my delegate tableView: didSelectRowAtIndexPath: method to dismiss the keyboard with resignFirstResponder sent to the last UITextField used.
Everything works ok if the cell with the last UITextField used is displayed.
Now, if I scroll down to bottom of the tableview and press on a row, then the resignFirstResponder is sent to a hidden UITextField and will not hide the keyboard. It doesn't throw an error also.
How can I hide the keyboard in such cases?

Have a look at UITextFieldDelegate and put the
[textField resignFirstResponder];
method in one of the callback functions. I particulary prefer:
- (BOOL)textFieldShouldReturn:(UITextField *)textField;

Did you try calling endEditing:YES method of the UITextField?

-(IBAction)hidekey:(id) sender{
[textField resignFirstResponder];
}
if you using Interface builder then checked outlet of text field and in .m file use above function and define for that text field. It will work.

Please use this tutorial to Create a return Key for UIKeyboardTypeNumberPad ! This should save a lot of time for you.

Related

after inputAccessoryView tapped

I have tried the solutions at UITextView doesn't show InputAccessoryView on first click
I'm having a with a problem with a textView who has a inputAccessoryView
I want to call [textView resignFirstResponder] through its inputAccessoryView,so that i can close the keyboard
and there is only a UIButton on the inputAccessoryView,and the tapping the button will invoke an IBAction method call -(IBAction)closeKeyboard:(id)sender;
now the sender in the method is the button on the inputAccessoryView,
question is ,
how can i find out this textView whose inputAccessoryView has been tapped,
or just get a pointed which is pointed to this textView,so i can call
[textView resignFirstResponder]??
You need to find the current first responder. If you have outlets to all your text views, you can ask each one in turn
if ([textView1 isFirstResponder])
[textView resignFirstResponder];
Though this may give you problems depending on your button (see here, but I haven't experienced this), if so use the editing property of the text view.

Multiple UIText fields with Multiple UIPickerViews in UITableView

I have a grouped style UITableView with a HeaderView that is loaded from another .xib.
The HeaderView has 4 UITextFields in it:
2 of the fields should display the Keyboard and allow user input.
2 of the fields should display a UIPickerView and update the UITextField with selection.
The Main TableView (with the sections and rows) is filled with UITextFields as well.
The UITextField in the first section (indexpath.section = 0) displays a UIPickerView
All other UITextFields in the rest of the sections/rows should display the Keyboard
I can get the Keyboard to display correctly and dismiss when the Done button is touched for all the UITextFields that can display the keyboard.
I can get the UIPickerView to display correctly and dismiss (with Custom Save/Cancel buttons).
The problem I have is when mixing the two...
When I do the following I have a hybrid effect:
Step 1: Touch the first UITextField to begin to enter data with the Keybard.
Step 2: Enter some data in the UITextField.
Step 3: Touch a UITextField that displays a UIPickerView instead of the Keyboard.
The result is the Keyboard AND my custom UIPickerView being displayed at the same time with the Keyboard actually displaying ON TOP of my UIPicker!
Any suggestions on how to prevent this from happening?
Need to show some code, but most likely you're not calling [myTextField resignFirstResponder] just before calling the UIPickerView.
You need to resign your keyboard for your textField. From the fact that you did not do it, I am guessing that you did not resign the pickerView as well. So you need to resign both of them or they will continue to stay on the screen
Resigning the textField.
Implement UITextFieldDelegate
Implement
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return 1;
}
Resigning pickerview:
Implement the picker view as your property and implement [self.yourpickerview resignFirstResponder] in textFieldDidEndEditing and in the IBAction of your custom DONE button for your picker view.

Getting didSelectRowAtIndexpath method called when textfield inside custom table view cell is focused

I have a custom tableviewcell with a label and a textfield. Right now I get callback in method didSelectRowAtIndexpath only when user clicks on cell outside of my textfield. When I touch on textfield this method is not called. So what should I do to get that method called when user touches on the textfield.
You want to read into UITextFieldDelegate and more specifically
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
and
- (void)textFieldDidBeginEditing:(UITextField *)textField
when those get called you can then do this on your UITableView
– selectRowAtIndexPath:animated:scrollPosition:
In cellForRowAtIndexPath method write
cell2.selectionStyle=UITableViewCellSelectionStyleNone;
for that row only

How to hide the iPhone keyboard? resignFirstResponder does not work

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.

Resigning responder of textview

How to resign virtual keyboard for text view? is there any way same as textfieldshouldresignresponder?
[aVariablePointingToAnObject resignFirstResponder];
aVariablePointingToAnObject being your UITextView (or another object that becomes the first responder)
or... if that is too confusing for you then please refer to this:
[textView resignFirstResponder];
UITextView and UITextField are both subclasses of UIResponder and both support resignFirstResponder.