Hi, there are two different textfields in my applications and i set the .delegate property of both of them to: self. Now i implemented different methods from the uitextfielddelegate protocol but i want to be able to control the two textfields individually. For instance i want the first text field to do something different when editing begins than the second textfield... Is the only solution to this problem to set the assign a different delegate or is there a way to do this with both of the textfield having the same delegate assigned to them? I hope my question is understandable i tried it to explain the best way that i could..... thanks in advance!
A:
Set a tag
on the textfield on initialization, then check the UITextField
object that is passed into the delegate method's tag
, then you'll be able to make a differentiation between the two textfields:
#define FIELD_ONE_TAG 1
#define FIELD_TWO_TAG 2
UITextField *textFieldOne = ...
textFieldOne.tag = FIELD_ONE_TAG;
...
UITextField *textFieldTwo = ...
textFieldTwo.tag = FIELD_TWO_TAG;
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField.tag == FIELD_ONE_TAG) { //field one
} else {//field two
}
}
Jacob Relkin
2010-09-19 20:28:36
Sounds good but how exactly do i set a tag and how do i check the tag?
Christoph v
2010-09-19 20:35:26
Thank you very much!
Christoph v
2010-09-19 20:44:21
@Christoph v Please upvote as well, thanks!
Jacob Relkin
2010-09-19 20:44:43
A:
UITextField *textFieldOne=.....
UITextField *textFieldTwo=....
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField == textFieldOne)
{ // field one code
}else{
//field two code
}
}
have two references of the inserted text views and u can compare them at the delegate methods. Not much needed with tags
Nareshkumar
2010-09-20 09:53:56