1

これは私のコードです:

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];

ボタンを離したときにボタン自体を削除するにはどうすればよいですか?

ありがとう、ボグダン

4

1 に答える 1

3

セレクターを

@selector(buttonUp:)

次に、メソッド定義で

- (void)buttonUp:(UIButton*)sender

追加

[sender removeFromSuperview]
于 2013-02-11T03:33:57.280 に答える