Search code examples
iosuitextfielduitextfielddelegate

How do I identify which textField triggered textFieldDidEndEditing on dynamically created UITableCell containing 2 uiTextFields?


I am on iOS 6 xcode 4.6.2 using storyboards.

I am using a dynamic UITableView which consists of a number of cells each of which have two UITextFields on them. The two fields are defined in a custom cell as

@property (strong, nonatomic) IBOutlet UITextField *lowRangeField;

@property (strong, nonatomic) IBOutlet UITextField *highRangeField;

I wish to use

-(void) textFieldDidEndEditing:(UITextField*) textfield

to get at the values and save it into a core data store.

Now, obviously, I can get at the value and assign it where I like, because I have the pointer to the textfield. My issue is I don't know how to identify which field on the cell this actually is. I know I can get the textfields superview to identify which cell its on , so I can work out which set of lowRangeField and highRangeField it is but then I get stuck.


Solution

  • My issue is I don't know how to identify which field on the cell this actually is.

    Use Tag to Identify.

    lowRangeField.tag = 1;
    highRangeField.tag = 2;
    
    
    -(void) textFieldDidEndEditing:(UITextField*) textfield
    {
    if (textField.tag == 1) {
    NSLog(@" clicked in lowRangeField"); 
    
    } else if (textField.tag ==2) {
     NSLog(@" clicked in highRangeField");
    }
    }