Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call textFieldDidEndEditing of UITextField when press UIButton

Is there anyway to call textFieldDidEndEditing of UITextField when pressed UIButton?

Current process is function in textFieldDidEndEditing can work when user press "Return" or "Done" button and click on UIButton. To make it clear, if ABC function in textFieldDidEndEditing to be run, user must press "Return" or "Done" button of Keyboard and then click on UIButton.

What I want is I want to run function in textFieldDidEndEditing can work when user press UIButton.

like image 359
PPShein Avatar asked Jun 16 '15 03:06

PPShein


1 Answers

In the button handler method, call:

[self.view endEditing:YES];

This will force the keyboard to disappear and whatever the current text field had the focus will resign first responder and the textFieldDidEndEditing: method will be called for it.

The above assumes the button handler is in the view controller class.

Since you are dealing with a custom cell and the button is in the custom cell, simply do:

[self endEditing:YES];

where self is the custom cell. This will resign any text field in the cell.

like image 169
rmaddy Avatar answered Oct 19 '22 23:10

rmaddy