0

ビュー内に numberButtons の行を動的に作成しました。任意の数字をクリックするとボタンが強調表示されます。その行で複数のボタンをクリックすると、クリックしたすべてのボタンが強調表示されます。複数の強調表示を避けるにはどうすればよいですか?

次のようにコードを使用しました

-(void)pressed:(id)sender{
    UIButton *button = (UIButton *)sender;
    if(!button.selected){

        [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(highlightButton:) userInfo:button repeats:NO];        

    } else {
        [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(unhighlightButton:) userInfo:button repeats:NO];
    }
-(void)highlightButton:(id)sender{
    UIButton *button = (UIButton *)[sender userInfo];
    button.highlighted = YES;
    button.selected = YES;
}
-(void)unhighlightButton:(id)sender{
    UIButton *button = (UIButton *)[sender userInfo];
    button.highlighted = NO;
    button.selected = NO;
}
4

2 に答える 2

1

前のハイライトを削除せずに、タップしたすべてのボタンがハイライトされることを意味していると思います。

一度に 1 つのボタンだけを強調表示する。どのボタンが強調表示されたかを追跡し、別のボタンをタップしたときにその強調表示を削除します。

- (void)buttonTapped:(UIButton *)button {
    if (button != [self lastSelectedButton]) { // don't re-highlight the same button
        // remove the highlight of "lastSelectedButton"

        [self setLastSelectedButton:button];
        // add the highlight to "lastSelectedButton" (not updated to the new button)
    }

    // Do the rest of you button logic here ...
}
于 2012-04-25T07:12:40.583 に答える
0

最後に deselect メソッドを呼び出して、select メソッドをオーバーライドします。そのため、コントロールをクリックすると、すぐに選択および選択解除されます。

于 2012-04-25T07:26:06.453 に答える