Search code examples
iosiphoneuitableviewuistepper

How to Unhide stepper when we select particular row in tableview


I have created a stepper in a CustomCell of a UITableView. However, I would like the stepper to only be visible when a particular row is selected. To this end, I tried the following:

In tableView:cellForRowAtIndexPath:

cell.customStepper.hidden=NO;

and in tableView:didSelectRowAtIndexPath:

cell.customStepper.hidden=YES;

But the stepper is still hidden. What am I missing?


Solution

  • @interface BRNCategoryViewController ()
    {      
      NSMutableArray *arySelectCategory;
      NSMutableArray *aryCategory;
    }
    
     - (void) viewDidLoad
    {
         arySelectCategory=[NSMutableArray new];
    }
    
    
     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
     {
         return aryCategory.count;
     }
    
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        BRNCategoryCell *cell=[[BRNCategoryCell alloc]initWithOwner:self];
    
         if ([arySelectCategory containsObject:[aryCategory objectAtIndex:indexPath.row]])
          {
               cell.customStepper.hidden = NO;
          }
          else
          {
               cell.customStepper.hidden = YES;
          }
    
                return cell;
    
      }
    
    
    
     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
     {
          [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
          if ([arySelectCategory containsObject:[aryCategory objectAtIndex:indexPath.row]])
          {
               [arySelectCategory removeObject:[aryCategory objectAtIndex:indexPath.row]];
          }
          else
          {
               [arySelectCategory addObject:[aryCategory objectAtIndex:indexPath.row]];
          }
                [tblEventCategory reloadData];
     }