美文网首页
iOS-TableViewCell取消点击高亮状态

iOS-TableViewCell取消点击高亮状态

作者: jazzfly | 来源:发表于2018-09-11 10:46 被阅读0次

今天需要点击UItableVeiwCell取消选中时的高亮状态,把方法分享一下
有两种方法, 我使用了第一种.第二种给大家也看看
1. 自定义cell 继承UITableViewCell
重写

 - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
    {

    }
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

        }

里面不写任何东西
注意重写的时候一定要有带animated 方法,不然还是无效

2.点击单元格 取消选中单元格

  //  点击单元格的时候取消选中单元格
 -(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

3.设置tableView的allowsSelection属性

 self.tableView.allowsSelection = NO;

4.取消系统UITableViewCell的高亮状态
cell.selectionStyle = UITableViewCellSelectionStyleNone;

相关文章

网友评论

      本文标题:iOS-TableViewCell取消点击高亮状态

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