怎样取消UITableViewCell的选中状态?

点击Cell是被选中的cell的背景会是灰色的,怎样取消Cell 的选中状态?

阅读 39.1k
3 个回答

只需要在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath中加入一行代码就可以了[tableView deselectRowAtIndexPath:indexPath animated:YES]; 然后再写你其他代码就可以了

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    //其他代码
}

设置cell的选中属性为如下就没有点击效果了
cell.selectionStyle = UITableViewCellSelectionStyleNone;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题