3

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

2 Answers 2

10

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
6

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

2
  • -(BOOL)textFieldShouldReturn:(UITextField *)textField; Apr 16, 2010 at 4:20
  • @drawnonward - right, textFieldShouldReturn: is a better fit for what he's asking than textFieldDidEndEditing:; I'll edit that in. Apr 16, 2010 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.