【发布时间】:2011-12-12 23:06:04
【问题描述】:
我的 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];
}
}
【问题讨论】:
标签: iphone objective-c cocoa-touch uitextfield