title: using objc_setAssociatedObject to pass UIButton @selector argument for UITableViewCell
body: <p>I'm attempting to implement a suggestion in this post: <a href="https://stackoverflow.com/questions/12297511/pass-an-argument-to-selector/12297575#12297575">Pass an argument to selector</a> to pass an <code>@selector</code> argument to a <code>UIButton</code> in a <code>UITableViewCell</code> using <code>objc_setAssociatedObject</code> and <code>objc_getAssociatedObject</code>.  The way I have it coded, it always ends up passing the row of whatever the last cell was that it created/loaded.  Here is my code:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      UILabel *mainLabel;
      soundButton=[UIButton buttonWithType:UIButtonTypeCustom];
  
      if (cell == nil){
  
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      soundButton.tag = 33;
          [soundButton addTarget:self action:@selector(soundButtonAction) forControlEvents:UIControlEventTouchUpInside];
          [soundButton setFrame:CGRectMake(210,3,68, 37)];
  
           [soundButton setBackgroundImage:[UIImage imageNamed:@"musicNote"] forState:UIControlStateNormal];
  
           [cell.contentView addSubview:soundButton];
      } else {
  
          soundButton = (UIButton *)[cell.contentView viewWithTag:33];
      }
      objc_setAssociatedObject(soundButton, "IndexPath", indexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
      return cell;
  }
  
  -(void)soundButtonAction
  {
      NSIndexPath *ip = objc_getAssociatedObject(soundButton, "IndexPath");
  </code></pre>