title: UIButton click sender always go to selected option
body: <p>I have a UIButton click sender as below:-</p>
  
  <pre><code>-(IBAction)clipButtonClick:(UIButton *)sender
  {
      sender.selected  = ! sender.selected;
  
      if (sender.selected)
      {
          [btnClipCategory setImage:[UIImage imageNamed:@"imgClip_HL"] forState:UIControlStateSelected];
  
          NSMutableArray* indexArray = [NSMutableArray array];
          for (NSInteger i = 0; i &lt; self.arySubCategory.count; i++)
          {
              [aryCheckCategoryList replaceObjectAtIndex:i withObject:@"YES"];
              NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
              [indexArray addObject:indexPath];
  
              dispatch_async(dispatch_get_main_queue(), ^{
                  [self.rightTableView reloadData];
              });
  
          }
  
      }
      else
      {
          [btnClipCategory setImage:[UIImage imageNamed:@"imgClip"] forState:UIControlStateNormal];
  
          NSMutableArray* indexArray = [NSMutableArray array];
          for (NSInteger i = 0; i &lt; self.arySubCategory.count; i++)
          {
              [aryCheckCategoryList replaceObjectAtIndex:i withObject:@"NO"];
              NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
              [indexArray addObject:indexPath];
  
  
  
              dispatch_async(dispatch_get_main_queue(), ^{
                  [self.rightTableView reloadData];
  
              });
  
          }
  
      }
  }
  </code></pre>
  
  <p>When I clicked on the button, sender will always hit on selected option.</p>
  
  <p>If i change the sender to code to sample code as below, my apps will working properly as expected. Any idea? Please help. Thank you.</p>
  
  <pre><code>-(IBAction)clipButtonClick:(UIButton *)sender
  {
      sender.selected  = ! sender.selected;
  
      if (sender.selected)
      {
          [btnClipCategory setImage:[UIImage imageNamed:@"imgClip_HL"] forState:UIControlStateSelected];
          NSLog(@"Selected. Will Hit here");
  
      }
      else
      {
          [btnClipCategory setImage:[UIImage imageNamed:@"imgClip"] forState:UIControlStateNormal];
          NSLog(@"Non Selected. Will Hit here");
  
      }
  }
  </code></pre>
  
  <p><strong>Edited</strong>
  I put my button under willDisplayHeaderView.</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
  
      UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
  
      btnClipCategory = [UIButton buttonWithType:UIButtonTypeCustom];
      [btnClipCategory setFrame:CGRectMake(header.frame.size.width - 45, header.frame.size.height * 0.2, ScreenW * 0.1, ScreenW * 0.1)];
  
      [btnClipCategory addTarget:self action:@selector(clipButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  
      [header addSubview:btnClipCategory];
  
  }
  </code></pre>