Match game tap bug

I built the match game following the video, but there is a bug that I tap one card, it won’t flip until I tap another one. Does anyone know what happend? And how to solve it?

Can you show us your code where you have the flip functions?

The viewcontroller is as below:

import UIKit

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

@IBOutlet weak var collectionView: UICollectionView!

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

override func viewDidLoad() {
    // Do any additional setup after loading the view.
    //call the getCard method of the card model,给上面声明的变量赋值
    cardArray = model.getCards()
    collectionView.delegate = self
    collectionView.dataSource = self
override func didReceiveMemoryWarning() {
    //dispose of any resource that can be recreated.

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return cardArray.count

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> 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 the cell
    return 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{
        card.isFlipped = true
    }else {
        card.isFlipped = false