title: How to delete cells on UICollectionView
body: <p>I created a button on every cell that onClick let the users delete a cell of my UICollectionView, where I initialize the cell I used the following code in order to pass the indexPath.item to the button method:</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
      CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
  
  
  
      // Configure the cell
      FidelityProducts *item = _feedItems[indexPath.item];
      NSLog(@"index dell'item:%ld", (long)indexPath.item);
  
      cell.deleteProduct.tag = indexPath.item;
      NSLog(@"TAG ASSEGNATO AL BOTTONE: %d",cell.deleteProduct.tag);
      [cell.deleteProduct addTarget:self action:@selector(DeleteProductFromArray:)
       forControlEvents:UIControlEventTouchUpInside];
  
      return cell;
  }
  </code></pre>
  
  <p>Then on the <code>DeleteProductFromArray</code> I created the following logic in order to delete the cells:</p>
  
  <pre><code>- (void)DeleteProductFromArray:(UIButton *)button {
  
      [_feedItems removeObjectAtIndex:button.tag];
  
      //check for the Column (can be 0 or 1)
      if(button.tag % 2 == 0)
      {
          IndexColumn = 0;
      }
      else
      {
          IndexColumn = 1;
      }
  
      //check for the Row
      if(button.tag &gt; 1)
      {
          IndexRow = button.tag/2;
      }
      if(button.tag &lt;= 1)
      {
          IndexRow = 0;
      }
      NSLog(@"button column =%d", IndexColumn);
      NSLog(@"button row =%d", IndexRow);
  
      [self.customCollectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:IndexColumn inSection:IndexRow]]];
  
  }
  </code></pre>
  
  <p>Now, I know that this will cause problem because the button tags aren't updated when I remove an item from my NSMutableArray but I just need to know why The first time that I try to delete a Cell the number 1 and 2 are cancelled but if I click on a cell > 3 the app crashes with the following error:</p>
  
  <pre><code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete item 0 from section 2, but there are only 1 sections before the update
  </code></pre>