Ios 未调用Swift-UICollectionView didSelectItemAt
当我点击卡片翻转时,我遇到了一个问题。did select函数没有被调用,因为我测试了它的打印功能,它显示它根本没有点击。是否可以提供一些帮助?如果collectionview启用了用户交互,请检查情节提要,对于单元格也是如此。viewcontroller是否继承了Ios 未调用Swift-UICollectionView didSelectItemAt,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,当我点击卡片翻转时,我遇到了一个问题。did select函数没有被调用,因为我测试了它的打印功能,它显示它根本没有点击。是否可以提供一些帮助?如果collectionview启用了用户交互,请检查情节提要,对于单元格也是如此。viewcontroller是否继承了UICollectionViewDelegate和UICollectionViewDataSource?检查单元格的内容视图(添加到单元格的元素)是否阻止点击手势通过,导致collectionview单元格无法识别点击手势 @IBOu
UICollectionViewDelegate
和UICollectionViewDataSource
?检查单元格的内容视图(添加到单元格的元素)是否阻止点击手势通过,导致collectionview单元格无法识别点击手势
@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()
}
}