【问题标题】:Table View Cells Not Selectable After Resigning UITextView as First Responder将 UITextView 作为第一响应者后,表格视图单元格不可选择
【发布时间】:2017-12-07 00:10:27
【问题描述】:

我在 UITableViewCell 中有一个 UITextView。我已将其设置为在选择单元格时成为第一响应者:

TPNTableViewCell *thisCell = (TPNTableViewCell *)[tblMain cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

thisCell.txtHidden.text=@"";
[thisCell.txtHidden becomeFirstResponder];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goAwayKeyboard)];
[self.view addGestureRecognizer:tap];

所以当单元格被选中时,txtHidden 成为第一响应者。然后当您单击键盘外时会触发选择器 goAwayKeyboard。

-(void)goAwayKeyboard
{
    TPNTableViewCell *thisCell = (TPNTableViewCell *)[tblMain cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    [thisCell.txtHidden resignFirstResponder];
}

这可行,但是在键盘退出后,我无法再选择表格视图中的单元格。我可以滚动表格视图,但无法选择单元格,我不知道为什么。

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    点击手势识别器在添加到视图后可能会吞噬所有触摸事件。也许在-goAwayKeyboard 中删除它会恢复触摸交互。

    【讨论】:

    • 所以我尝试将属性添加到视图控制器@property UIGestureRecognizer *tap,然后在goAwayKeyboard中我做了[self.view removeGestureRecognizer:tap]; .但这也没有用。我还尝试将表格视图设置为第一响应者,但没有奏效。奇怪的是表格视图仍然拖动它只是不响应点击。
    • 没关系。我不小心调用了两次添加手势识别器的函数。傻我。谢谢!
    【解决方案2】:

    您应该禁用离开键盘中的点击手势,您可以在以下代码的帮助下做到这一点,

    tap.enabled = NO;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多