美文网首页iOS经验总结
uitableview消除点击时候的灰色效果

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

作者: 我一不小心就 | 来源:发表于2018-04-03 15:01 被阅读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.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.imageView.image = [UIImage imageNamed:self.meImgsArr[indexPath.section][indexPath.row]];
        cell.textLabel.text = self.meDataSource[indexPath.section][indexPath.row];
        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/vwzqhftx.html