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

    xiaoxiao2021-11-29  44

    我们在显示table的cell时,不需要设置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]; } 二、直接在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法里面加上一句:cell.selectionStyle = UITableViewCellSelectionStyleNone;也能达到效果。 if (!cell) { cell = [[YunEvaluateListCell alloc]initWithFrame:CGRectMake(0, 0, Wi, 40]; } cell.selectionStyle = UITableViewCellSelectionStyleNone;
    转载请注明原文地址: https://ju.6miu.com/read-678765.html

    最新回复(0)