我有一个关于这个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
}
使用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