title: UITableView button duplicates while scrolling
body: <p>I have created custom buttons for each viewcell(1 per cell). When scrolling the UITableView some viewcells have 2 buttons and that was not intended. I fail to see the error in my ways.</p>
  
  <p>Please help!</p>
  
  <p>Image: <a href="http://s18.postimg.org/v7djg84ah/buttons_App.png" rel="nofollow">http://s18.postimg.org/v7djg84ah/buttons_App.png</a></p>
  
  <p>Header:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface ViewController : UIViewController &lt;UITableViewDataSource&gt;
  
  - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView;
  
  - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section;
  
  - (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
  
  - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
  -(void)checkboxSelected:(id)sender;
  @end
  </code></pre>
  
  <p>Implementation</p>
  
  <pre><code>#import "ViewController.h"
  
  #define sectionCount  1
  #define itemSection  0
  
  @interface ViewController ()
  {
      NSArray *items;
  }
  @end
  
  @implementation ViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      items = @[@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2",@"itemdd", @"item2"];
  
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
  {
      return sectionCount;
  }
  
  - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      switch(section)
      {
          case itemSection:
          {
              return [items count];
          }
  
          default:
              return 0;
  
      }
  }
  
  -(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  {
      switch (section)
      {
          case itemSection:
              return @"Items";
          default:
              return @"woot";
      }
  }
  
  
  -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"itemCell"];
  
      switch(indexPath.section)
      {
          case itemSection:
              cell.textLabel.text = items[indexPath.row];
              break;
          default:
              cell.textLabel.text=@"Unknown";
      }
  NSInteger x,y;
  
      x =cell.frame.origin.x +100; y = cell.frame.origin.y + 10;
      UIButton *checkbox;
  
      checkbox = [[UIButton alloc] initWithFrame:(CGRectMake(x,y,20,20))];
  
      [checkbox setBackgroundImage:[UIImage imageNamed:@"notSelectedButton.png"]forState:UIControlStateNormal];
  
      [checkbox setBackgroundImage:[UIImage imageNamed:@"checkedButton.png"]forState:UIControlStateSelected];
      [checkbox setBackgroundImage:[UIImage imageNamed:@"uncheckedButton.png"]forState:UIControlStateHighlighted];
  
      checkbox.adjustsImageWhenHighlighted = YES;
      [checkbox addTarget:self action:@selector(checkboxSelected:) forControlEvents:UIControlEventTouchDown];
      [cell.contentView addSubview:checkbox];
  
      return cell;
  }
  
  -(void)checkboxSelected:(id)sender
  {
      bool selected = [(UIButton *)sender isSelected];
      if (selected)
      {
          [(UIButton *)sender setSelected:false];
      }
      else
      {
          [(UIButton *)sender setSelected:true];
      }
  
  
  }
  @end
  </code></pre>