首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView选择和取消选择行

问UITableView选择和取消选择行
EN

Stack Overflow用户
提问于 2013-12-16 04:47:46
回答 2查看 27.8K关注 0票数 17

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

所以当你触摸UITableViewCell时,我希望它被选中并高亮显示,然后当用户举起手指时,我想取消选择和取消高亮显示UITableViewCell。

这就是我到目前为止正在做的事情,并且取消选择可以工作,但是单元格仍然高亮显示。

代码语言:javascript
复制
#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];

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-16 04:54:21

代码语言:javascript
复制
-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:
    (NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

这是一个无限循环,我很确定。然而..。它在某种程度上是正确的。您可以将该方法调用转移到didSelectRowAtIndexPath:中。

代码语言:javascript
复制
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
    (NSIndexPath *)indexPath {
    //stuff
    //as last line:
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

因此,可以在您希望取消选中该行的任何时间从任何位置调用deselectRowAtIndexPath。

代码语言:javascript
复制
[self.myTableView deselectRowAtIndexPath:[self.myTableView 
    indexPathForSelectedRow] animated: YES];
票数 34
EN

Stack Overflow用户

发布于 2017-04-19 15:11:43

方法您需要取消选择 didSelectRowAtIndexPath 上的行

示例代码

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20599597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档