tableView的cell点击选择选项,改变图形和选择点击事件

@interface VipMoneyViewController (){

 UIButton *_preBtn;

}

@property (assign, nonatomic) NSInteger selectRow;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//价格列表
          VipChargeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellTwo"];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;
          
          VipModel *model = self.arrayModel[indexPath.row - 1];
          cell.monLabel.text = model.months;
          cell.moneyLabel.text = model.price;
          
          //          [cell setModel:model];
          //          self.selectRow = indexPath.row;
          //判断点击选择图形
          if (indexPath.row == 1) {
               _preBtn = cell.chooseBtn;
          }
          cell.chooseBtn.tag = indexPath.row;
          if (indexPath.row == _selectRow) {
               if(_selectRow == 1){
                    [cell.chooseBtn  setBackgroundImage:[UIImage imageNamed:@"icon_choose_go"]forState:UIControlStateNormal];
                    
                    VipModel *model = self.arrayModel[indexPath.row-1 ];
                    self.vip_id = model.vip_id;
               }else{
                    [cell.chooseBtn  setBackgroundImage:[UIImage imageNamed:@"icon_choose_go"]forState:UIControlStateNormal];                 
               }
          }else{
               [cell.chooseBtn  setBackgroundImage:[UIImage imageNamed:@"icon_choose_normal"]forState:UIControlStateNormal];
              
          }
          return cell;
     }
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     if (indexPath.row == 0||indexPath.row > 3) {
          return;
     }
     
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
     self.selectRow = indexPath.row;
     VipModel *model = self.arrayModel[indexPath.row - 1];
     self.vip_id = model.vip_id;
     UIButton *btnSelect = [self.view viewWithTag:indexPath.row];
     [btnSelect setBackgroundImage:[UIImage imageNamed:@"icon_choose_go"] forState:UIControlStateNormal];
     if (_preBtn) {
          [_preBtn setBackgroundImage:[UIImage imageNamed:@"icon_choose_normal"] forState:UIControlStateNormal];
     }
     _preBtn = btnSelect;
//     [tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; //放弃自动刷新
 
}

你可能感兴趣的:(tableView的cell点击选择选项,改变图形和选择点击事件)