0

我正在做一个项目,比如寻找测验答案。它将随机生成带有 3 个选项的问题。如果答案是正确的分数将是1。如果答案是不正确的分数将减少。如果 score 小于等于 0,则 UIAlert 将显示“You loss”。

问题:

但不幸的是,如果我点击正确的答案,UIAlert 也会显示“你输了”。如果我的回答是正确的,我的分数也不会增加。这也是我的viewcontroller.swift声明,所以 if 语句也是如此。我不知道我还是错过了什么。

if 条件下需要:

  • 如果答案是正确的,它应该通过显示增加uialert
  • 如果答案是错误的,它应该通过显示减少uialert
  • 如果分数 <=uialert显示“你输了”的消息
  • 如果分数为 == 200uialert则显示“你赢了”的消息

这只是我想在我的代码中声明。但我试过它对我不起作用!

4

1 回答 1

0

首先,您的帖子不清楚您需要什么。在考虑我的回答“格伦”解决方案之前也是最好的。因此,让我 从您的问题中的 if 条件部分假设您的需求。我已经用我的解决方案检查了这段代码,它运行良好。在这里,我将通过一些示例为您的问题提供解决方案。您尝试根据您的要求重新更改它。

@IBAction func clickbutton(sender: UIButton)

{

    if sender.tag == matching
 {

    // please initialize before  ( var anyname : string = “”) 

    anyname = “Correct"

      ++score

 } 

    else if score >= 1 

{

    anyname = "Wrong"

    --score


 }

      else if (score <= 0 && sender.tag == correctAnswer)

 {

      anyname = " Correct Nice Try"

      ++score

}

    // initialize var notmatching = 0 before

     else if(score <= 0 || sender.tag == notmatching) 

{

      score = 0
     anyname = “losser"
    print(" oops 0")

}

     else if score == 4 {

     print("winner")

    anyname = “winner”

    score = 0

    ++score

 }
      else 
{


        // you can make another condition or leave it
}



    // here make UIAlert for all condition with their  title name : anything

 }

证明答案不好。所以你自己试试,让我知道。

于 2015-10-08T11:44:33.010 回答