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;
}