Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView选择并取消选择行_Ios_Uitableview - Fatal编程技术网

Ios UITableView选择并取消选择行

Ios UITableView选择并取消选择行,ios,uitableview,Ios,Uitableview,我有一个UITableViewcell,它在触摸后保持高亮显示。我想知道如何删除突出显示后,你的触摸变得可见的权利 因此,当您触摸UITableViewCell时,我希望它被选中并高亮显示,然后当用户抬起手指时,我希望取消选中并取消高亮显示UITableViewCell 这就是我目前正在做的,取消选择可以工作,但是单元格仍然高亮显示 #pragma mark -- select row - (void) tableView:(UITableView *)tableView didSelectRo

我有一个UITableViewcell,它在触摸后保持高亮显示。我想知道如何删除突出显示后,你的触摸变得可见的权利

因此,当您触摸UITableViewCell时,我希望它被选中并高亮显示,然后当用户抬起手指时,我希望取消选中并取消高亮显示UITableViewCell

这就是我目前正在做的,取消选择可以工作,但是单元格仍然高亮显示

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