使用随机描述

时间:2016-03-16 18:49:56

标签: ios arrays swift

类ViewController:UIViewController {

@IBOutlet weak var ImgSing: UIImageView!

@IBOutlet weak var descrLblSign: UILabel!



var questionModel = QuestionModel()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

//我一直试图让它在屏幕上显示随机图像的描述,但我无法弄清楚如何做到这一点。还在学习编程。

    for _ in 1...5 {
        randomQuestion(queModel: questionModel)

    }


}


func randomQuestion(queModel queModel:QuestionModel){

    let questions = queModel.questions
    let randomIndex = Int(arc4random_uniform(UInt32(questions.count)))

    descrLblSign.text = "\(questions[randomIndex].answers[questions[randomIndex].correctAnswerIndex])"

    ImgSing.image = questions[randomIndex].question






}

0 个答案:

没有答案