У меня есть UITextField внутри моего UITableViewCell в приложении для iPad. Если я ввожу текст, а затем нажимаю кнопку отклонения клавиатуры, он сохраняет текст, но если я нажимаю, чтобы изменить вид без предварительного отклонения клавиатуры, текст не сохраняется.
Я использую этот код, чтобы попытаться отказаться от textField в качестве первого респондента, но не повезло.
- (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];
}
}