mardi 23 février 2016

Swift: how to show randomly1 or 3 items?

I have this code. But it works not correctly. I need only once that items not hide, but show them from 1 to 3 randomly.

if items.count > 0 && aiDeciding == false {
    if buttonCount < 3 {
        sender.hidden = true            
        if let index = items.indexOf(sender) {
            items.removeAtIndex(index)        
            if sender.hidden == true {                       
                let numberToInsert = Int(arc4random_uniform(UInt32(3))) + 1
                let tag = Int(arc4random_uniform(UInt32(items.count)))
                for _ in 0..<numberToInsert {
                    items[tag].hidden = false 
                    items.append(items[tag]) // it appends only index of items, but not show the items on the screen.
                }
            }
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire