简体   繁体   中英

Table View Cells Not Selectable After Resigning UITextView as First Responder

I have a UITextView in a UITableViewCell. I have set it to become first responder when the cell is selected as so:

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];

So when the cell is selected txtHidden becomes first responder. And then the selector goAwayKeyboard is triggered when you click out of the keyboard.

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

This works, however after the keyboard is resigned I can no longer select a cell in the table view. I can scroll the table view, but the cells aren't selectable and I can't figure out why.

The tap gesture recognizer is probably swallowing all touch events after it's added to the view. Perhaps removing it in -goAwayKeyboard would restore touch interaction.

您应该在走开键盘中禁用点击手势,可以在以下代码的帮助下完成此操作,

tap.enabled = NO;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM