@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 не вызывается, поскольку я протестировал ее на функцию печати, и это показывает, что она вообще не используется. Может ли помочь, пожалуйста?