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

后端 未结 2 356
生来不讨喜
生来不讨喜 2021-01-06 19:56

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

相关标签:
2条回答
  • 2021-01-06 20:22

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

    0 讨论(0)
  • 2021-01-06 20:24

    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.

    0 讨论(0)
提交回复
热议问题