title: iOS: How to handle multiple buttons created dynamically with one iBAction?
body: <p>I have created radio and check box buttons programmatically according to my web service response, where number of buttons varies. </p>
  
  <p>Following is the code to create those buttons:</p>
  
  <pre><code>for(int j = 0; j &lt; nintOptionCount; j++)
      {
          UILabel * lblOption =  [[UILabel alloc] initWithFrame: CGRectMake(50, yLabel, 250, 21)];
          //lblOption.backgroundColor = [UIColor yellowColor];
          lblOption.text = [arrmOptionName objectAtIndex:j];
          lblOption.textColor = [UIColor blackColor];
          lblOption.font = [UIFont systemFontOfSize:14.0f];
          [viewDetail addSubview:lblOption];            
  
  
          intOptionId = [[arrmOptionId objectAtIndex:j] intValue];
  
          if (intEventChoice == 1)
          {
              btnRadio = [[UIButton alloc]initWithFrame:CGRectMake(5, yLabel, 22, 22)];
              [btnRadio addTarget:self action:@selector(radioButtonPress:) forControlEvents:UIControlEventTouchUpInside];
              [btnRadio setImage:[UIImage imageNamed:@"btn_radio.png"] forState:UIControlStateNormal];
              [btnRadio setTag:intOptionId];
              [btnRadio setTitle:[NSString stringWithFormat:@"radio%d%d",intOptionId,intParamId] forState:UIControlStateNormal];
              [viewDetail addSubview:btnRadio];
          }
          else
          {
              btnCheckBox = [[UIButton alloc]initWithFrame:CGRectMake(5, yLabel, 22, 22)];
              [btnCheckBox setImage:[UIImage imageNamed:@"btn_checkbox.png"] forState:UIControlStateNormal];
              [btnCheckBox addTarget:self action:@selector(checkBoxButtonPress:) forControlEvents:UIControlEventTouchUpInside];
              [btnCheckBox setTag:intOptionId];
              [btnCheckBox setTitle:[NSString stringWithFormat:@"check%d,%d",intOptionId,intParamId] forState:UIControlStateNormal];
              [viewDetail addSubview:btnCheckBox];
          }
  
          yLabel = yLabel+ 21+10;
      }
  </code></pre>
  
  <p>So, my question is how to handle action on those buttons where buttons are created programmatically? and how to handle selection and deselection of buttons as those buttons are work like radio buttons and check box buttons.
  in case of radio button if i select one then other needs to be deselect and in case of check box, selection and deselection of check box needs to be managed.</p>
  
  <p>I have tried with setting tag to buttons but its not working properly as i expect.</p>
  
  <p>Please provide me some solution.
  Thanks in advance.</p>