I want to call a method when the done button is clicked in the UITextField KeyBoard? Please Help me...
+3
A:
See the UITextFieldDelegate Protocol reference. You probably want to implement the – textFieldShouldReturn:
method in your delegate.
David Gelhar
2010-04-16 04:13:46
-(BOOL)textFieldShouldReturn:(UITextField *)textField;
drawnonward
2010-04-16 04:20:21
@drawnonward - right, textFieldShouldReturn: is a better fit for what he's asking than textFieldDidEndEditing:; I'll edit that in.
David Gelhar
2010-04-16 04:41:59
Thanks a lot i was able to do it...
Pradeep Reddy Kypa
2010-04-16 04:48:04
+2
A:
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.
Jay O'Conor
2010-04-16 06:22:59