Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide keyboard/ resignFirstResponder forcibly

i'm working on an app which has a tableView with a textField in the right side of its each cell(there are more than 20 cells). i've created custom cell's for each row except for the last one. In the last row there is only a button.

Now i want to call resignFirstResponder on the button's click.
What should i do Please help?

like image 934
TechMan Avatar asked Nov 29 '25 00:11

TechMan


2 Answers

You will have to keep track of which textfield in which cell has the first responder and resign it like this.

[myCellTextField resignFirstResponder];
like image 158
Totumus Maximus Avatar answered Nov 30 '25 15:11

Totumus Maximus


You probably want to keep track of the text field with the keyboard. Implement the <UITextFieldDelegate> protocol in your controller, and set the controller as each of the text fields' delegates. Write the textFieldDidBeginEditing: method like so, setting an instance variable called currentTextField:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    currentTextField = [textField retain];
}

Then, in your action for the button run [currentTextField resignFirstResponder].

like image 33
aopsfan Avatar answered Nov 30 '25 15:11

aopsfan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!