How to call a method when the Done Button in the KeyBoard is Clicked?

落爺英雄遲暮 提交于 2019-12-03 21:49:10

问题


I want to call a method when the done button is clicked in the UITextField KeyBoard? Please Help me...


回答1:


It's not even necessary to implement the delegate. I greatly prefer using good, old-fashioned target/action pattern to handle this. It can also lead to cleaner code if you have multiple ways of ending editing (say, intercepting touches outside the text field to cancel editing).

To use target/action, simply wire up UIControlEventEditingDidEndOnExit, which shows up in Interface Builder as the Did End On Exit event.

No muss, no fuss. A lot cleaner and easier than implementing the delegate.




回答2:


See the UITextFieldDelegate Protocol reference. You probably want to implement the – textFieldShouldReturn: method in your delegate.



来源:https://stackoverflow.com/questions/2650513/how-to-call-a-method-when-the-done-button-in-the-keyboard-is-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!