views:

68

answers:

1

Hi,

I have run-time created buttons in a View, placed in a grid-looking way. Now I want the user to have the possibility to delete each and every one of them by choosing. How can I identify to one the user have chosen to properly delete it out from View? I use Tag property in the creating process.

Thank you.

+1  A: 

here's one way to do it. When making a button, set the action to the view or whichever class is controlling the button pushing logic:

UIButton *theButton = [UIButton buttonWithType:(UIButtonType)];
[theButton addTarget:self action:@selector(deleteMe:) forControlEvents:(UIControlEvents)];

then, implement the deleteMe: method somewhere in your class:

-(void)deleteMe:(id)sender
{
  //remove the button.  sender is the button that was pushed.
}
pxl