0

I have 2 text fields in my app and both are connected with my "devTyping" IBAction. This method (I guess it is a method) will be called when the event "editing changed" happens.

How can I tell my method, in which text field the user is typing?

- (IBAction)devTyping {
    NSLog(@"How to know in which text field the user is typing?");
}
Benjamin
  • 3
  • 1
  • 2

2 Answers2

1

Take a look at this question, which should be an equivalent as to what you are asking :)

Community
  • 1
  • 1
Stian Storrvik
  • 2,199
  • 2
  • 14
  • 21
  • Exactly so—I'd go with the tag option. Checking for integer equality on something that you're probably never going to change/look at again is better than using an arbitrary method on the instance variables of a class. – FeifanZ Apr 05 '11 at 22:53
1

You could declare the method like this:

- (IBAction)devTyping:(UITextField*)sender {
     NSLog(@"The user is typing in text field %d",sender.tag);
}

And assign each textfield a tag in Interface Builder, which is just a number to identify the text field (or any other element).

mvds
  • 45,755
  • 8
  • 102
  • 111