iOS---UITableView 取消点击cell的选中背景颜色

链接:https://www.jianshu.com/p/e37e729935f6


在点击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;也能达到效果。


设置UITableViewCell的选中背景颜色的方法:

UIView *view = [[UIView alloc]init];
view.backgroundColor=[UIColor redColor];
cell.selectedBackgroundView=view;




猜你喜欢

转载自blog.csdn.net/iotjin/article/details/80806881
今日推荐