美文网首页iOS 菜鸟之旅
tableViewCell的长按点击效果

tableViewCell的长按点击效果

作者: 涛涛灬灬 | 来源:发表于2017-07-20 17:48 被阅读7次
  • (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;
    }

相关文章

网友评论

    本文标题:tableViewCell的长按点击效果

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