Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 讯息是:";失败!“再玩一次”;得分时不显示<;3._Ios_Swift_Alert - Fatal编程技术网

Ios 讯息是:";失败!“再玩一次”;得分时不显示<;3.

Ios 讯息是:";失败!“再玩一次”;得分时不显示<;3.,ios,swift,alert,Ios,Swift,Alert,我是iOS Swift新手,当得分

我是iOS Swift新手,当
得分<3
时,“失败!再次播放”消息不会显示

func discussScore(sender: AnyObject){       
  // after asking all questions, if score >=20, the player accesses stage 2
    if (questionField.text == listOfQuestions[4]) {
          if (score >= 3) {
              //go to next step
          }

          if (score < 3) {
              alertMessageWrong("Fail! Play Again") // (here's my problem)
          }                    
     }
}

func alertMessageWrong(theMessage2: String) {

    let alertController = UIAlertController(title: " ", message:theMessage2, preferredStyle: UIAlertControllerStyle.Alert)
    alertController.view.tintColor = UIColor.redColor()
    alertController.addAction(UIAlertAction(title:theMessage2, style: UIAlertActionStyle.Default,handler: nil))
    self.presentViewController(alertController, animated: true, completion: nil)

}
func discusscore(发送方:AnyObject){
//问完所有问题后,如果分数>=20,玩家进入第2阶段
if(questionField.text==问题列表[4]){
如果(分数>=3){
//转到下一步
}
如果(分数<3){
AlertMessageError(“失败!再次播放”)/(这是我的问题)
}                    
}
}
func AlertMessage错误(消息2:字符串){
让alertController=UIAlertController(标题:,消息:theMessage2,首选样式:UIAlertControllerStyle.Alert)
alertController.view.tintColor=UIColor.redColor()
addAction(UIAlertAction(标题:theMessage2,样式:UIAlertActionStyle.Default,处理程序:nil))
self.presentViewController(alertController,动画:true,完成:nil)
}

首先,我在这行放一个断点:

if (questionField.text == listOfQuestions[4])
穿过每一条线,看看走哪条路。。。您可以看到如何调试

要检查您是否找到了正确的问题,最好使用“步长”整数,而不是比较字符串。在回答每个问题后递增此整数。然后你可以检查你是否在最后一个问题上做:

if currentStep >= listOfQuestions.count { ... }
其次,如果您执行以下操作,代码将更干净:

let minimumScore = 3
if score < minimumScore { 
    showAlert()
    return
}
// go to next step.
minimumScore=3
如果得分<最小得分{
showarert()
返回
}
//转到下一步。

首先,我在这行放一个断点:

if (questionField.text == listOfQuestions[4])
穿过每一条线,看看走哪条路。。。您可以看到如何调试

要检查您是否找到了正确的问题,最好使用“步长”整数,而不是比较字符串。在回答每个问题后递增此整数。然后你可以检查你是否在最后一个问题上做:

if currentStep >= listOfQuestions.count { ... }
其次,如果您执行以下操作,代码将更干净:

let minimumScore = 3
if score < minimumScore { 
    showAlert()
    return
}
// go to next step.
minimumScore=3
如果得分<最小得分{
showarert()
返回
}
//转到下一步。

第二个
如果
与第一个正好相反,我建议您使用
else
,这样您就可以确定将执行一个或另一个代码块。@cjnevin我以前做过({code}if(questionField.text==listOfQuestions[4]){code}),但我的算法太厚,所以我决定创建一个func discusscore()。当我编译完所有代码后,除了不显示第二个
的警告消息(如果
与第一个正好相反),我建议您使用
else
,这样您就可以确保执行一个或另一个代码块。@cjnevin我以前做过({code}if(questionField.text==listOfQuestions[4]){code})但是我的算法太厚,所以我决定创建一个func discussScore().当我编译时,所有的工作都很好,除了警报消息没有display@cjnevin-Dan Beaulieu NiñoScript已经有一条警告消息显示答案是否错误。你认为这是我第二条警告消息(“失败!再次播放”)的原因吗不显示?这也可能是问题的原因,您是否在控制台中看到警告?我已检查,但没有警告。您是否中断了代码?请在警报应显示的位置打印一张图片,然后查看您是否在控制台中看到。@cjnevin Dan Beaulieu NiñoScript已经有一条警报消息显示答案是否错误。您认为这是我的第二条警报消息(“失败!再次播放”)未显示的原因吗?这也可能是导致问题的原因,您是否在控制台中看到警告?我检查了,但没有警告。您是否中断了代码?在警报应显示的位置打印,然后查看您是否在控制台中看到警告。