键盘正在显示,因为用户点击了文本字段,而不是因为他们选择了一个单元格。这就是为什么 allowsSelection 不影响它。
allowsSelection
移动 UITextFieldDelegate 处理你的 UITableViewController 。然后,您可以轻松决定是否显示日期选择器:
UITextFieldDelegate
UITableViewController
textFieldShouldBeginEditing(_:)
false
我将UITextFieldDelegate移动到TableViewController并在其中包含以下代码:
-(bool) textFieldShouldBeginEditing:(UITextField *)textField { if (self.TableViewDiary.allowsSelection) { return true; } else { CGPoint buttonPosition = [textField convertPoint:CGPointZero toView:self.TableViewDiary]; NSIndexPath *indexPath = [self.TableViewDiary indexPathForRowAtPoint:buttonPosition]; ActivityDiaryCell *cell = [self.TableViewDiary cellForRowAtIndexPath:indexPath]; if ([cell.TextFieldStartDt isFirstResponder] || [cell.TextFieldEndDt isFirstResponder]) { return true; } } return false; } - (void)textFieldDidBeginEditing:(UITextField *)textField { CGPoint buttonPosition = [textField convertPoint:CGPointZero toView:self.TableViewDiary]; NSIndexPath *indexPath = [self.TableViewDiary indexPathForRowAtPoint:buttonPosition]; ActivityDiaryCell *cell = [self.TableViewDiary cellForRowAtIndexPath:indexPath]; [cell setSelected:YES animated:NO]; } - (void)textFieldDidEndEditing:(UITextField *)textField { CGPoint buttonPosition = [textField convertPoint:CGPointZero toView:self.TableViewDiary]; NSIndexPath *indexPath = [self.TableViewDiary indexPathForRowAtPoint:buttonPosition]; ActivityDiaryCell *cell = [self.TableViewDiary cellForRowAtIndexPath:indexPath]; [cell setSelected:NO animated:YES]; }