lundi 18 mai 2015

Randomly choosing one outlet and setting others

I have a function that chooses a random button and sets its character to a certain emoji. I want to now set the remaining UIButtons to be random emojis.

How would I determine which UIButtons were not set from the random generator assigning one a value?

Also I want to make sure that the value being assigned is not the same as the value that was inserted at the random generator.

@IBOutlet weak var topLeftAnswer: UIButton!
@IBOutlet weak var topRightAnswer: UIButton!
@IBOutlet weak var bottomLeftAnswer: UIButton!
@IBOutlet weak var bottomRightAnswer: UIButton!

 func correctAnswerGen() {
    var correct: UInt32 = arc4random_uniform(4)
    switch correct{
    case 0: topLeftAnswer.setTitle("😄", forState: UIControlState.Normal)
    case 1: topRightAnswer.setTitle("😄", forState: UIControlState.Normal)
    case 2: bottomLeftAnswer.setTitle("😄", forState: UIControlState.Normal)
    case 3: bottomRightAnswer.setTitle("😄", forState: UIControlState.Normal)
    default: break
    }
    //assign other 3 buttons to another emoji value.
}




Aucun commentaire:

Enregistrer un commentaire