0
votes

I have a UITextField inside of my UITableViewCell on my iPad app. If I enter text, then press the dismiss keyboard button, it saves the text, but if I click to change the view without dismissing the keyboard first, it is not saving the text.

I'm using this code to try resigning the textField as first responder but no luck.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (int it=0; it < [self.clinicalChecklist count]; ++it)
    {
        ClinicalChecklistCell *cell = (ClinicalChecklistCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:it inSection:0]];
        UITouch *touch = [[event allTouches] anyObject];
        if ([cell.col1_singleEntryValue isFirstResponder] && [touch view] != cell.col1_singleEntryValue) {
            [cell.col1_singleEntryValue resignFirstResponder];
        }
        if ([cell.col2_singleEntryValue isFirstResponder] && [touch view] != cell.col2_singleEntryValue) {
            [cell.col2_singleEntryValue resignFirstResponder];
        }
        if ([cell.col1_doubleEntryValue_1 isFirstResponder] && [touch view] != cell.col1_doubleEntryValue_1) {
            [cell.col1_doubleEntryValue_1 resignFirstResponder];
        }
        if ([cell.col1_doubleEntryValue_2 isFirstResponder] && [touch view] != cell.col1_doubleEntryValue_2) {
            [cell.col1_doubleEntryValue_2 resignFirstResponder];
        }
        if ([cell.col2_doubleEntryValue_1 isFirstResponder] && [touch view] != cell.col2_doubleEntryValue_1) {
            [cell.col2_doubleEntryValue_1 resignFirstResponder];
        }
        if ([cell.col2_doubleEntryValue_2 isFirstResponder] && [touch view] != cell.col2_doubleEntryValue_2) {
            [cell.col2_doubleEntryValue_2 resignFirstResponder];
        }
        [super touchesBegan:touches withEvent:event];
    }
}
1

1 Answers

0
votes

if you just want get the text of UITextField,

[myTextField addTarget:self action:@selector(getText) forControlEvents:UIControlEventEditingChanged];