title: Detect tap on a button in UITableViewCell for UITableView containing multiple sections
body: <p>I want to detect button tap on a UITableViewCell where the parent UITableView consists of multiple sections.</p>
  
  <p>I was able to do it in the case of single section, but I got into trouble determining the correct section where there were more than one.</p>
  
  <p>I am trying to determine the correct section corresponding to the UITableViewCell where the user has tapped on the button.</p>
  
  <p>Here is the updated code after the problem is being solved:</p>
  
  <pre><code>@property (strong, nonatomic) NSMutableArray* quantityArray;
  @property (strong, nonatomic) NSMutableArray* rows; 
  
  @synthesize quantityArray,rows;
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      quantityArray = [[NSMutableArray alloc] init];
      [self PluMinusFunction];
  }
  
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
          //
          // Some code here.
          //         
  
      if (addBtnClicked || minusBtnClicked) {
          cell.lblCount.text = [[quantityArray objectAtIndex:indexPath.section-1]objectAtIndex:indexPath.row];
          addBtnClicked = NO;
          minusBtnClicked = NO;
      } else {
          cell.lblCount.text = [[quantityArray objectAtIndex:indexPath.section-1]objectAtIndex:indexPath.row];                
      }
  
          cell.btnMinus.tag = indexPath.row;
          cell.btnPlus.tag = indexPath.row;
          cell.lblCount.tag = indexPath.row;
  
          [cell.btnPlus addTarget:self action:@selector(addItem:) forControlEvents:UIControlEventTouchUpInside];
  
          if ([ cell.lblCount.text integerValue]!=0) {
              [cell.btnMinus addTarget:self action:@selector(deleteItem:) forControlEvents:UIControlEventTouchUpInside];
          }
  
          return cell;
      }
  }
  
  #pragma mark - Plus Minus Button
  
  - (void)PluMinusFunction {
      for (int j=0; j &lt;[itemArr count]; j++) {
          rows = [[NSMutableArray alloc] init];
          for (int i=0; i &lt;[ [[itemArr objectAtIndex:j] objectForKey:@"itemList"]count]; i++) {
              [rows insertObject:@"0" atIndex:i];
          }
          [quantityArray insertObject:rows atIndex:j];
      }
      [self sum];
  }
  
  #pragma mark - UIButton selector
  
  - (void)addItem:(UIButton*)button {
      CGPoint touchPoint = [button convertPoint:CGPointZero toView:self.tableView];
      NSIndexPath *clickedButtonIndexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  
      NSInteger row = clickedButtonIndexPath.row;
      NSInteger section = clickedButtonIndexPath.section;
  
      NSInteger  LabelText =[[[quantityArray objectAtIndex:section-1]objectAtIndex:row]integerValue] + 1;
      NSMutableArray *subArray = [quantityArray objectAtIndex:section-1];
      [subArray replaceObjectAtIndex:row withObject: [NSString stringWithFormat:@"%ld",(long)LabelText]];
      [quantityArray replaceObjectAtIndex:section-1 withObject: subArray];
      addBtnClicked = YES;
  
      NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:row inSection:section];
      NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
      [self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
  }
  
  - (void)deleteItem:(UIButton*)button {
      CGPoint touchPoint = [button convertPoint:CGPointZero toView:self.tableView];
      NSIndexPath *clickedButtonIndexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  
      NSInteger row = clickedButtonIndexPath.row;
      NSInteger section = clickedButtonIndexPath.section;
  
      NSInteger  LabelValue =[[[quantityArray objectAtIndex:section-1]objectAtIndex:row]integerValue];
  
      if (LabelValue &gt;= 1) {
          NSInteger  LabelText =[[[quantityArray objectAtIndex:section-1]objectAtIndex:row]integerValue] - 1;
          NSMutableArray *subArray = [quantityArray objectAtIndex:section-1];
          [subArray replaceObjectAtIndex:row withObject: [NSString stringWithFormat:@"%ld",(long)LabelText]];
  
          [quantityArray replaceObjectAtIndex:section-1 withObject: subArray];
          addBtnClicked = YES;
  
          NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:row inSection:section];
          NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
          [self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
      }
  }
  </code></pre>
  
  <p>I want to achieve the layout as shown below:</p>
  
  <p><a href="https://i.stack.imgur.com/6jrzo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6jrzo.png" alt="enter image description here"></a></p>
  
  <p>This link gave the solution to my problem too:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1802707/detecting-which-uibutton-was-pressed-in-a-uitableview">Detecting which UIButton was pressed in a UITableView</a></li>
  </ul>