UITextField委托不工作
问题描述:
我在我的iPad应用程序的UITableViewCell里面有一个UITextField。如果我输入文本,然后按解除键盘按钮,它将保存文本,但如果我点击更改视图而不关闭键盘,它不会保存文本。UITextField委托不工作
我使用此代码尝试resigning 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];
}
}
答
如果你只是想获得的UITextField的文本,
[myTextField addTarget:self action:@selector(getText) forControlEvents:UIControlEventEditingChanged];