title: Adding custom edit and delete button in UITableViewCell
body: <p>I have a <code>UITableView</code> which contains the names of all countries.
  The user can delete or edit the name of country anytime by taping on the <code>cell</code>.</p>
  
  <p>My UITableView cell initially looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/fiBDL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fiBDL.png" alt="enter image description here"></a></p>
  
  <p>Now when user taps on it I am changing it like this:</p>
  
  <p><a href="https://i.stack.imgur.com/S1Nmk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S1Nmk.png" alt="enter image description here"></a></p>
  
  <p>I think I am following a very lame approach.Here is what I did:</p>
  
  <p>Declared globally buttons to add:</p>
  
  <pre><code> UIButton *btnDeleteWithImage,*btnDeleteWithText,*btnEditWithImage,*btnEditWihtText; //buttons
  </code></pre>
  
  <p>And a <code>NSMutableArray</code> to keep track of <code>indexPath.row</code></p>
  
  <p>Now in my didSelectMethod I am doing this:</p>
  
  <pre><code> //To change the background 
   UIView *selectionBackground = [[UIView alloc] init];
  
    selectionBackground.backgroundColor = [UIColor customColor];
  
   cell.selectedBackgroundView = selectionBackground;
  
   // to check which cell is pressed
  
  if([indexPathCollection containsObject:index])
  {
      [btnDeleteWithImage removeFromSuperview];
      [btnDeleteWithText removeFromSuperview];
      [btnEditWihtText removeFromSuperview];
      [btnEditWithImage removeFromSuperview];
      [indexPathCollection removeObject:index];
  
      [cell addSubview:btnDeleteWithImage];
      [cell addSubview:btnDeleteWithText];
      [cell addSubview:btnEditWithImage];
      [cell addSubview:btnEditWihtText];
      [indexPathCollection addObject:index];
  }
  else
  {
  
      [cell addSubview:btnDeleteWithImage];
      [cell addSubview:btnDeleteWithText];
      [cell addSubview:btnEditWithImage];
      [cell addSubview:btnEditWihtText];
      [indexPathCollection addObject:index];
  }
  </code></pre>
  
  <p>But this is not working good.When I scroll table edit and delete button randomly occurs. </p>
  
  <p>Did someone has better Idea how can achieve this in a very efficient way.</p>