iOS 开发技巧 - UITableView 取消点击cell的选中背景颜色

这个分享,依然是关于 UITableView 的。 应该有遇到过,在点击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抬起手指之后,就没有那个选中的灰色背景颜色了。

方法二:多谢Softwaretailor 提醒,我忘了之前使用过的一个简单设置方法了

直接在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法里面加上一句:cell.selectionStyle = UITableViewCellSelectionStyleNone;也能达到效果。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容