Ios UITableView选择并取消选择行
我有一个UITableViewcell,它在触摸后保持高亮显示。我想知道如何删除突出显示后,你的触摸变得可见的权利 因此,当您触摸UITableViewCell时,我希望它被选中并高亮显示,然后当用户抬起手指时,我希望取消选中并取消高亮显示UITableViewCell 这就是我目前正在做的,取消选择可以工作,但是单元格仍然高亮显示Ios UITableView选择并取消选择行,ios,uitableview,Ios,Uitableview,我有一个UITableViewcell,它在触摸后保持高亮显示。我想知道如何删除突出显示后,你的触摸变得可见的权利 因此,当您触摸UITableViewCell时,我希望它被选中并高亮显示,然后当用户抬起手指时,我希望取消选中并取消高亮显示UITableViewCell 这就是我目前正在做的,取消选择可以工作,但是单元格仍然高亮显示 #pragma mark -- select row - (void) tableView:(UITableView *)tableView didSelectRo
#pragma mark -- select row
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%@", indexPath);
NSLog(@"%@", cell.textLabel.text);
}
#pragma mark -- deselect row
-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
这是一个无限循环,我很确定。然而。。。这是在正确的轨道上。您可以将该方法调用移动到didselectrowatinexpath:
中
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
//stuff
//as last line:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
因此,可以在您希望取消选择行的任何时间从任何位置调用取消选择行IndexPath
[self.myTableView deselectRowAtIndexPath:[self.myTableView
indexPathForSelectedRow] animated: YES];
您需要取消选择
didselectrowatinexpath
method
示例代码
哦。。哎呀。我现在也看到了,哈哈
[self.myTableView deselectRowAtIndexPath:[self.myTableView
indexPathForSelectedRow] animated: YES];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}