views:

492

answers:

1

Hi...

I am calling an action from textFieldDidBeginEditing as follows:

[dotButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];

and specifiying my action as:

- (void) actionButton:(id)sender {
textField.text = [textField.text stringByAppendingString:@"APPROVED"];
}

Simple question with hopefully a simple answer....

textField.text refers to the field named textField but how do I update the current field that textFieldDidBeginEditing is acting on at the time?? i.e can I set a variable to retrieve the current fieldname?

Thanks

+1  A: 

You should check whether or not the textField the label of your interest. An example:

if (textField == self.firstLabel){
  //do something
}
else if (textField == self.secondLabel){
  //do other something
}

The textField variable that is passed from the delegate method is the one that you should handle.

Tell me if it works. Good luck!

sfa
Thanks but I'm pretty new to this (like a few weeks old!) can you through a bit of sample code at me to explain a little more what you mean by 'cast it to UITextField"?
Rosco
Insert this line of code before yours in -actionButton: and it should work automagically.
Costique
Sorry...Don't get ye Costique..what line of code, where? I like automagically...that would be super :)
Rosco
Hoang...the sender here is actually UIButton so it's causing debug errors now
Rosco
I edit the answer, sorry I misunderstood your code.
sfa
That's it Hoang. Thank you so much!
Rosco