0

我有一个数学问答游戏,我希望用户能够触摸按钮,现在只有当我将一个按钮设置为正确答案时它才会起作用。是否可以将其设置为按钮组合,例如答案是 53 用户可以触摸 5 按钮和 3 按钮。

视图控制器.m

-(IBAction)EasyLevel:(id)sender {

Question.hidden = NO;
SelectLevel.hidden = YES;

buttonOne.hidden = YES;
buttonTwo.hidden = YES;
buttonThree.hidden = YES;
buttonFour.hidden = YES;
buttonFive.hidden = YES;
buttonSix.hidden = YES;
buttonSeven.hidden = YES;
buttonEight.hidden = YES;
buttonNine.hidden = YES;
buttonZero.hidden = YES;

Right1.hidden = YES;
Right2.hidden = YES;
Right3.hidden = YES;
Right4.hidden = YES;
Right5.hidden = YES;
Right6.hidden = YES;
Right7.hidden = YES;
Right8.hidden = YES;
Right9.hidden = YES;
Right0.hidden = YES;

Wrong1.hidden = YES;
Wrong2.hidden = YES;
Wrong3.hidden = YES;
Wrong4.hidden = YES;
Wrong5.hidden = YES;
Wrong6.hidden = YES;
Wrong7.hidden = YES;
Wrong8.hidden = YES;
Wrong9.hidden = YES;
Wrong0.hidden = YES;



int EasyQuestion = arc4random() % 2 ;
switch (EasyQuestion) {

    case 0:
        Question.text = [NSString stringWithFormat: @"What is 4 X 2"];
        Right1.hidden = NO;

        Wrong3.hidden = NO;
        Wrong4.hidden = NO;
        Wrong5.hidden = NO;
        Wrong6.hidden = NO;
        Wrong7.hidden = NO;
        Wrong8.hidden = NO;
        Wrong9.hidden = NO;
        Wrong0.hidden = NO;

        buttonOne.hidden =  NO;
        buttonTwo.hidden =  NO;
        buttonThree.hidden =  NO;
        buttonFour.hidden =  NO;
        buttonFive.hidden =  NO;
        buttonSix.hidden =  NO;
        buttonSeven.hidden =   NO;
        buttonEight.hidden =  NO;
        buttonNine.hidden =  NO;
        buttonZero.hidden =  NO;

        buttonOne.text = [NSString stringWithFormat: @"1"];
        buttonTwo.text = [NSString stringWithFormat: @"2"];
        buttonThree.text = [NSString stringWithFormat: @"3"];
        buttonFour.text = [NSString stringWithFormat: @"4"];
        buttonFive.text = [NSString stringWithFormat: @"5"];
        buttonSix.text = [NSString stringWithFormat: @"6"];
        buttonSeven.text = [NSString stringWithFormat: @"7"];
        buttonEight.text = [NSString stringWithFormat: @"8"];
        buttonNine.text = [NSString stringWithFormat: @"9"];
        buttonZero.text = [NSString stringWithFormat: @"0"];
        break;

        case 1: .....
        default:
        break; }

任何帮助表示赞赏,谢谢 :) Stephanie

4

1 回答 1

0

诀窍是程序如何知道用户何时通过按键输入数字?

一种方法可能是使答案成为可编辑的文本字段(UITextField)并将焦点设置为它并将键盘设置为数字类型键盘(通过UITextInputTraitsUITextField 实现的协议),以便用户可以输入数字值。

如果您不想使用 iOS 键盘而只想使用自己的自定义按钮,那么您可以使用自己的按钮并让每个按钮的操作是将适当的数字附加到您可能在 UILabel 中显示的答案字符串和当他们按下按钮时更新。您希望有一个后退/删除按钮,以便他们可以擦除数字并在那里更新字符串。使用此模型,您可能会有一个“确定”按钮或“完成”按钮,以指示他们已完成并且当前字符串是他们的答案。该按钮将是在该点获取答案字符串中的字符串并检查它是否正确/不正确的按钮。

希望这足以让你继续前进!

于 2013-08-16T06:05:27.493 回答