Swift - UICollectionView didSelectItemAt не вызывается - PullRequest
0 голосов
/ 24 февраля 2020
@IBOutlet weak var collectionView: UICollectionView!

  var model = CardModel()

  //Kepp track of the cards veiwed
  var cardArray = [Card]()

  override func viewDidLoad() {
    super.viewDidLoad()

    //Call the getCards method of the card model

    cardArray = model.getCards()

    collectionView.delegate = self
    collectionView.dataSource = self
  }

   // MARK: -UICOlecctionView Protocol Methods

  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return cardArray.count
  }

  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    // Get a card 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 the card for the cell
    cell.setCard(card)

    return cell
  }

  func collectionView( _ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
   print("Cell is taped: \(indexPath.row)")

   let cell =  collectionView.cellForItem(at: indexPath) as! CardCollectionViewCell

    // Flip the card
    cell.flip()
  }
}

У меня возникает проблема, когда я нажимаю на карту, чтобы перевернуть. Функция did select не вызывается, поскольку я протестировал ее на функцию печати, и это показывает, что она вообще не используется. Может ли помочь, пожалуйста?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...