Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 334
SimonTheDiver Avatar asked May 17 '13 11:05

SimonTheDiver


2 Answers

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");
}
}
like image 142
Buntylm Avatar answered Nov 16 '22 00:11

Buntylm


Try this one

This is used to identify in which text field you have entered value .

- (void)viewDidLoad
{
    lowRangeField.tag = 100;
    highRangeField.tag = 200;
}

-(void) textFieldDidEndEditing:(UITextField*) textfield
{
     if (textField.tag == 100)
     {
        NSLog(@" clicked On lowRangeField"); 

     } 
     else if (textField.tag ==200) 
     {
         NSLog(@" clicked On highRangeField");
     }
}
like image 45
Dharmbir Singh Avatar answered Nov 15 '22 22:11

Dharmbir Singh