Pradeep Reddy Kypa
Pradeep Reddy Kypa

Reputation: 4022

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

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

Upvotes: 3

Views: 1775

Answers (2)

Jay O'Conor
Jay O'Conor

Reputation: 2495

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.

Upvotes: 10

David Gelhar
David Gelhar

Reputation: 27900

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

Upvotes: 6

Related Questions