我最初问的问题是“如何制作没有正确答案的测验应用程序”,从那以后我就知道那不是正确的方法。我试图做的是一个测验,根据您选择的答案,建议某位艺术家听。我为所有按钮授予了不同的分数,因此,如果您在某个范围内得分,就会被推荐为某个艺术家。然后我的脑海中响起,如果我使用了一个分数以外的其他度量,则可以使分数更易于计算。因此,我为每个艺术家指定了自己的类别,然后根据您按下的按钮,给该类别一个分数。
例如
else if quuis > 3 { let alert = UIAlertController(title: "Check Out Quis Christ", message: "Quis Christ has a style of hip hip reminiscent of the golden age of lyricism and hard beats. Quis makes every line count with hard rhymes that any hip hop purist can enjoy", preferredStyle: .alert)
let restartAction = UIAlertAction(title: "restart", style: .default
, handler: { UIAlertAction in self.startOver()})
alert.addAction(restartAction)
present(alert, animated: true, completion: nil)
startButton.isHidden = false
}else if mojoI > 3 { let alert = UIAlertController(title: "Check Out Mojofree", message: "MoJo Free has a trap soul sound that feeds your curiosity if SZA and Erykah Badu came together and fused. She has raw lyricism and smooth voice that makes for a great listening experience ", preferredStyle: .alert)
let restartAction = UIAlertAction(title: "restart", style: .default
, handler: { UIAlertAction in self.startOver()})
alert.addAction(restartAction)
present(alert, animated: true, completion: nil)
startButton.isHidden = false
}else if billyI > 3 { let alert = UIAlertController(title: "Check Out Billypalmtrees", message: "Billypalmtrees has a rap style that can be compared to the great lupe fiasco with witty wordplay and infectious flow. He also is a hybrid artist who can also sing with smooth voice that you can sit back and enjoy", preferredStyle: .alert)
let restartAction = UIAlertAction(title: "restart", style: .default
, handler: { UIAlertAction in self.startOver()})
alert.addAction(restartAction)
present(alert, animated: true, completion: nil)
startButton.isHidden = false
}else if rebelI > 3 { let alert = UIAlertController(title: "Check Out Rebel Kuzco", message: "Rebel Kuzco has a new age rap style that keeps your nodding your head and singing along to any hit that plays from him. With catchy hooks complimented by high energy rhymes makes for a great listening experience.", preferredStyle: .alert)
let restartAction = UIAlertAction(title: "restart", style: .default
, handler: { UIAlertAction in self.startOver()})
alert.addAction(restartAction)
present(alert, animated: true, completion: nil)
startButton.isHidden = false
}
我遇到的问题是只有10个问题,我决定如果分数大于3,建议艺术家,但只有10个问题,分数的空间足够接近结果可能是多个分数超过3分。我知道我可以将其提高到更高的阈值,但是id想要做的是弄清楚如何编写它,以便它选择得分最高的那个,而不只是得分超过某个数字的那个!
我怎么写出来?用通俗易懂的英语(而不是代码),我脑子里的东西就是
“如果此分数大于此,该,此和该分数,则显示此警报。”
答案 0 :(得分:0)
让您入门:
`
class Question {
let questionText = ""
let answer = 0
}
`
然后在ViewController中将按钮挂接到IB操作。给每个按钮一个不同的标签。还要在IB行动中提问:
let newQuestion = Question()
if sender.tag == 1 {
//User picked answer 1
newQuestion.answer = 1
}
然后为2,3,4做其他事情
那应该使您朝着正确的方向前进