CristiC
CristiC

Reputation: 22698

UITableViewCell and resignFirstResponder

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?

Upvotes: 4

Views: 3565

Answers (4)

Teodor Kostov
Teodor Kostov

Reputation: 313

Have a look at UITextFieldDelegate and put the

[textField resignFirstResponder];

method in one of the callback functions. I particulary prefer:

- (BOOL)textFieldShouldReturn:(UITextField *)textField;

Upvotes: 4

Legolas
Legolas

Reputation: 12325

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

Upvotes: 0

ram
ram

Reputation: 1193

-(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.

Upvotes: 0

Manlio
Manlio

Reputation: 10865

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

Upvotes: 0

Related Questions