在点击cell得时候,默认会有一个选中状态的背景颜色,一般是灰色的,怎么取消呢?
方法一:
在 Table view data source
的 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
方法里直接调用[tableView deselectRowAtIndexPath:indexPath animated:NO];
就可以了。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
OK,效果完成,之后点击cell抬起手指之后,就没有那个选中的灰色背景颜色了。
方法二:
直接在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
方法里面加上一句:cell.selectionStyle = UITableViewCellSelectionStyleNone;
也能达到效果。
转载:https://www.jianshu.com/p/e37e729935f6