views:

270

answers:

2

My iphone app has several text fields. The "Did End on Exit" event on each text field calls a single action. How can I tell which text field called the action? Can I detect this from the sender object which is passed to the action?

+3  A: 

Sure, just set a tag (NSInteger) on each of the text fields, and then check against them on the sender object.

Look for more details under the documentation for UIView's tag property.

jpm
+6  A: 

The sender object will be the UITextField in question. If you have a bunch of IBOutlets connecting to your text fields, you can simply compare if sender == aField to see which field it is.

Kevin Ballard
note this is assuming you define your action methods like so:- (IBAction) myAction:(id)senderYou can then compare "sender" to whatever IBOutlet UITextField *variable you've defined to attach the text field to in IB.
Kendall Helmstetter Gelner