Bogdan Vitoc
Bogdan Vitoc

Reputation: 139

How to make a UIButton Delete Itself

So this is my code:

for (int x = 1; x < 100; x++) {
        int randomX = arc4random() %280;
        int randomY = arc4random() %500;

        UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [myButton setTitle:string forState:UIControlStateNormal];
        myButton.frame = CGRectMake(randomX, randomY, 40.0, 40.0);
        [myButton addTarget:self action:@selector(buttonUp) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:myButton];

How do I make the buttons delete themselves when let go?

Thanks, Bogdan

Upvotes: 1

Views: 179

Answers (1)

Darren
Darren

Reputation: 10129

Change the selector to

@selector(buttonUp:)

Then in your method definition

- (void)buttonUp:(UIButton*)sender

add

[sender removeFromSuperview]

Upvotes: 3

Related Questions