tableViewCell的长按点击效果

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellID = @"cell";
    CYTLiveRewardChartTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
    cell = [[CYTLiveRewardChartTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }

      cell.level.text = [NSString stringWithFormat:@"%ld",indexPath.row + 4];
      cell.name.text = [self.viewModel nameForAtIndex:indexPath];
      cell.money.text = [self.viewModel goldStrForRowAtIndex:indexPath];
    

选中的样式一定不能是none 而是UITableViewCellSelectionStyleDefault
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}

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

  • (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
    self.selectionStyle = UITableViewCellSelectionStyleDefault;
    self.selectedBackgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height)];
    self.selectedBackgroundView.backgroundColor = kCYTCardPressedColor;
    self.contentView.backgroundColor = kCYTCardColor;
    self.backgroundColor = kCYTCardPressedColor;
    }
    return self;
    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容