如何解决这个“不能下标类型的值`[[字符串]]`与类型的索引,`UInt32`”

问题描述 投票:-3回答:1

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

        }
swift xcode9
1个回答
0
投票

使用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
© www.soinside.com 2019 - 2024. All rights reserved.