gpt4 book ai didi

ios - UITableView 选择和取消选择行

转载 作者:IT王子 更新时间:2023-10-29 08:14:28 26 4
gpt4 key购买 nike

我有一个 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];

}

最佳答案

-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:
(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

这是一个无限循环,我很确定。然而......它有点在正确的轨道上。您可以将该方法调用移至 didSelectRowAtIndexPath:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
//stuff
//as last line:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

就此而言,您可以随时随地调用 deselectRowAtIndexPath 以取消选择该行。

[self.myTableView deselectRowAtIndexPath:[self.myTableView 
indexPathForSelectedRow] animated: YES];

关于ios - UITableView 选择和取消选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20599597/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com