title: How to remove the button pragmatically with tag
body: <p>I am adding button subView to each row I click. I am trying to remove the button subView every time once I click on different row and add button subview to the other row I click.</p>
  
  <p>Where would be my issue? It is adding subView to each row without removing any of them.</p>
  
  <pre><code>if (sender.tag == 212)
    {
      myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      myButton2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  
      //Debug shows that every-time myButton&amp;myButton2 hasn't tag??
  
      if (myButton2.tag != 0  &amp;&amp; myButton.tag != 0)
      {
          [myButton removeFromSuperview];
          [myButton2 removeFromSuperview];
      }
  
      UITableViewCell *cell = (id)sender.superview.superview.superview;
  
      CGPoint center= sender.center;
      CGPoint rootViewPoint = [sender.superview convertPoint:center toView:commonTable.table];
      NSIndexPath *indexPath1 = [commonTable.table indexPathForRowAtPoint:rootViewPoint];
  
      itemdata1 = [itemList objectAtIndex:indexPath1.row];
  
      if (closeManager) [closeManager release];
  
      CGFloat __y = commonTable.y + commonTable.table.y - commonTable.table.contentOffset.y + cell.height*indexPath1.row + sender.y;
      CGFloat __x = commonTable.x + commonTable.table.x + sender.x;
      CGRect layerBox1 = CGRectMake(618, __y, 90, sender.height+3);
      CGRect layerBox2 = CGRectMake(888, __y, 94, sender.height+3);
  
      NSLog(@"%f and %f", __x, __y);
  
      myButton.frame = layerBox1;
      [[myButton layer] setBorderWidth:2.0f];
      myButton.layer.borderColor = [UIColor redColor].CGColor;
      [myButton addTarget:self action:@selector(func1:) forControlEvents:UIControlEventTouchUpInside];
  
      myButton2.frame = layerBox2;
      [[myButton2 layer] setBorderWidth:2.0f];
      [myButton2 addTarget:self action:@selector(func2:) forControlEvents:UIControlEventTouchUpInside];
      myButton2.layer.borderColor = [UIColor redColor].CGColor;
  
      [self addSubview:myButton];
      [self addSubview:myButton2];
  
      myButton.tag = myButton2.tag = 666;
  
  }
  </code></pre>
  
  <p>Edited for Bhumeshwer katre:</p>
  
  <pre><code>    if (myButton&amp;&amp;myButton2)
      {
          [myButton removeFromSuperview];
          [myButton2 removeFromSuperview];
      }
  
      //Other variables 
  
      if(!myButton){
          myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
          myButton.frame = layerBox1;
          [[myButton layer] setBorderWidth:2.0f];
          myButton.layer.borderColor = [UIColor redColor].CGColor;
          [myButton addTarget:self action:@selector(func1:) forControlEvents:UIControlEventTouchUpInside];
          myButton.tag = 666;
          [self addSubview:myButton];
      }
  </code></pre>