我对此UInt32
有疑问,
我的按钮中的“答案”出现了以下错误:“无法为索引为[[String]]
的类型为UInt32
的下标”
let answers = [["1. After the exam, I felt too exhausted and famished to eat my foods.","2. I could eat a horse, I am a famish now.","3. I famished my stomach next time you treat me to a meal out.","4. I will bring lots of pizza, that's famish."],["Would","Has to","Must","Could"]]
var rightanswerplacement:UInt32 = 0
rightanswerplacement = arc4random_uniform(2)+1
var button:UIButton = UIButton()
var x = 1
for i in 1...3{
button = view.viewWithTag(i) as! UIButton
if (i == Int(rightanswerplacement)){
button.setTitle(answers[rightanswerplacement][0], for: UIControlState.normal)
}
else{
button.setTitle(answers[rightanswerplacement][x], for: UIControlState.normal)
x = 2
}
currentquestions += 1
}
答案 0 :(得分:0)
将 Int 用于下标。
注意:我删除了视图以测试Int的正确性。
let answers = [["1. After the exam, I felt too exhausted and famished to eat my foods.","2. I could eat a horse, I am a famish now.","3. I famished my stomach next time you treat me to a meal out.","4. I will bring lots of pizza, that's famish."],["Would","Has to","Must","Could"]]
var rightanswerplacement: Int = 0
rightanswerplacement = Int(arc4random_uniform(2)) + 1
var x = 1
for i in 1...3 {
if (i == Int(rightanswerplacement)) {
print(answers[rightanswerplacement][0])
} else {
print(answers[rightanswerplacement][x])
x = 2
}
}
输出
Would
Has to
Must