Home > Mobile >  Novice [help] flip elimination game UI click has a bug
Novice [help] flip elimination game UI click has a bug

Time:09-23

Recently followed a blogger tubing is swift wrote flip elimination game, but encounter a bug, is always the main points of this card have no reaction, I only ordered the next card on the card will turn it over, ah, what is a power to make it so capricious!!!!!! Mina SAN, please help to see the code,,, red part is click on the card code,
The import UIKit

Class ViewController: UIViewController, UICollectionViewDelegate UICollectionViewDataSource {

@ IBOutlet weak var collectionView: UICollectionView!

Var model=CardModel ()
Var cardArray=[Card] ()

Override func viewDidLoad () {
Super viewDidLoad ()

CardArray=model. GetCards ()

CollectionView. Delegate=self
CollectionView. The dataSource=self

}
Override func didReceiveMemoryWarning () {
Super. DidReceiveMemoryWarning ()
//the dispose of any resource that can be recreated.
}

Brush the//here is the new item
Func collectionView (_ collectionView: UICollectionView, numberOfItemsInSection section: Int) - & gt; Int {

Return cardArray. Count
}

//here is operation to set collectionviewcell
Func collectionView (_ collectionView: UICollectionView, cellForItemAt indexPath: indexPath) - & gt; UICollectionViewCell {

//get a CardCollectionViewCell object
Let cell=collectionView. DequeueReusableCell (withReuseIdentifier: "cardCell", for: indexPath) as! CardCollectionViewCell

//get the card that the collection view is trying to display
Let card=cardArray [indexPath row]

//set that card for cell
Cell. SetCard (card)

Return the cell
}

func collectionView (_ collectionView: UICollectionView, didDeselectItemAt indexPath: indexPath) {

Let cell=collectionView. CellForItem (at: indexPath) as! CardCollectionViewCell

Let card=cardArray [indexPath row]

If card. IsFlipped==false {
Cell. Flip ()
Card. IsFlipped=true
} else {
Cell. Flipback ()
Card. IsFlipped=false
}

}


}
  •  Tags:  
  • iOS
  • Related