title: Passing id to button action method in Objective-C
body: <p>I have UIButtons programatically created. Now, I created an method to trigger for the button like so:</p>
  
  <pre><code>-(void)createButton {
  //code to create button
  [mybutton addTarget:self action:@selector(myAction:)forState:UIControlStateNormal];
  }
  
  -(void)myAction:(id)sender {
  if([tag sender] == 0) {
  posX = 380;
  } else if(....... //set posX to different values
  }
  [self.myScroll setContentOffset:CGPointMake(poxX, 0) animated:YES];
  </code></pre>
  
  <p>That's pretty much what the buttons do aside from loading data. Basically, I am using the buttons as tabs. If I tap on a button, it slides to the center. In one of these buttons, there's an "update buttons" button where I can add and remove more buttons. If I tap on one of the buttons, it would automatically be removed and if I tap add, one would automatically add. There's no problem with that. The thing is, I want to retain the "update buttons" button centered as it is technically still the selected button. Here's how the method inside the view for update buttons: </p>
  
  <pre><code>-(void)updateButtons {
  NSUInteger index = [self.anArray indexOfObject:@"btnChange"];
  id indexId = [NSNumber numberWithInteger: index];
  //this following line causes the app to crash because it does not recognize the indexId I'm trying to set
  [self myAction:indexId];
  }
  </code></pre>
  
  <p>Everytime I execute the updateButtons function and myAction is triggered, the app crashes with an uncaught exception. So my question is, how can I properly pass an id to an action method?</p>