我的iPad应用程序中的UITableViewCell内部有一个UITextField。如果我输入文字,然后按下解除键盘按钮,它会保存文字,但如果我点击更改视图而不先取消键盘,则表示不保存文字。
我正在使用此代码尝试将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];
}
}
答案 0 :(得分:0)
如果您只想获取UITextField的文本,
[myTextField addTarget:self action:@selector(getText) forControlEvents:UIControlEventEditingChanged];