美文网首页
uitableview消除点击时候的灰色效果

uitableview消除点击时候的灰色效果

作者: HelloWong | 来源:发表于2021-04-15 11:18 被阅读0次

方案1:
在- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath 加 cell.selectionStyle = UITableViewCellSelectionStyleNone;

注意:该方案是彻底干掉灰色背景

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

方案二:修改- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
方法中加[tableView deselectRowAtIndexPath:indexPath animated:NO];

注意:该方案是抬手以后没有灰色背景

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

相关文章

网友评论

      本文标题:uitableview消除点击时候的灰色效果

      本文链接:https://www.haomeiwen.com/subject/adddlltx.html