【问题标题】:How to finish highlight from selected button when new button is selected?选择新按钮时如何完成选定按钮的突出显示?
【发布时间】:2012-07-09 11:27:24
【问题描述】:
-(IBAction)choiceOne:(id)sender{

    if ([Choice2 isSelected]) {
        [Choice2 performSelector:@selector(finishHighlight:) withObject:sender afterDelay:0];
        score = score -4;
        score = score+8;
        NSLog(@"Score updated %i touched from choice 1 ",score);
        [self performSelector:@selector(doHighlight:) withObject:sender afterDelay:0];

        checker =1 ;

    }else if ([Choice3 isSelected]) {
          [Choice3 performSelector:@selector(finishHighlight:) withObject:sender afterDelay:0];
        score = score -2;
        score = score+8;
        NSLog(@"Score updated %i touched from choice 1 ",score);
        [self performSelector:@selector(doHighlight:) withObject:sender afterDelay:0];

        checker =1 ;
    }
    else {
        score = score+8;
        NSLog(@"Score updated %i touched from choice 1 ",score);
        [self performSelector:@selector(doHighlight:) withObject:sender afterDelay:0];

        checker =1 ;
    }


}

如果从菜单中按下任何其他按钮,我必须从所选按钮完成突出显示

- (void)doHighlight:(UIButton*)b {
    [b setHighlighted:YES];
}    
-(void)finishHighlight:(UIButton*)a{

    [a setHighlighted:NO];

}

这些是我在上面使用的功能......和

【问题讨论】:

  • 我认为您同时调用了相同的操作

标签: iphone uibutton highlighting activity-finish


【解决方案1】:

如果两个按钮都连接到“IBOutlets”,这将非常容易。他们是吗? 比如:

IBOutlet UIButton * mode1;
IBOutlet UIButton * mode2;

参数 a 和 b 在此特定中被忽略...

-(IBAction) button1Pressed:(id)sender {

    [self performSelector:@selector(highlightButton1:) withObject:sender afterDelay:0.0];
}

- (void)highlightButton1:(UIButton *)a { 
        [mode1 setHighlighted:YES];
    [mode2 setHighlited:NO];
}
-(IBAction) button2Pressed:(id)sender {

    [self performSelector:@selector(highlightButton2:) withObject:sender afterDelay:0.0];
}

- (void)highlightButton2:(UIButton *)b { 
    [mode1 setHighlighted:NO];
    [mode2 setHighlited:YES];
}

【讨论】:

    【解决方案2】:

    是的.. 只需使用迭代来获取按钮并将它们设置为正常,或者您可以拥有一个实例变量来存储先前选择的按钮。所以你只需要改变这个按钮的状态。因此,由您决定哪种方法更适合您。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 2016-10-27
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      相关资源
      最近更新 更多