tags:

views:

33

answers:

1

In my specific case, how do I identify or know which UITextField is being referenced in shouldChangeCharactersInRange method?

I know the parameter (UITextField*)textField contains the object being referenced, but how do I compare to identify which one it is?

+1  A: 
  1. If you create your interface using IB then you can create IBOutlet in your controller for each UI element, connect then in IB and later compare textField parameters with them:

    //header
    IBOutlet UITextField* nameField;
    IBOutlet UITextField* addressField;
    
    
    //Implementation
    ...
    if (textField == nameField){
    }
    if (textField == addressField){
    }
    

2 In IB you can also assign a unique tag value for each UITextField (available for each UIView subclasses) and compare tag values:

    #define nameTag 10
    #define addressTag 11

    //Implementation
    ...
    if (textField.tag == nameTag){
    }
    if (textField.tag == addressTag){
    }
Vladimir
Bah you beat me to it again Vladimir :)
willcodejavaforfood
Ah I forgot about tags, but I wanted a better way to do it. I didn't realize I could just compare the reference name. Thank you Vladimir.
just_another_coder