UICollectionView Highligh或Select单元格错误

时间:2016-05-08 12:44:10

标签: ios swift uicollectionview uicollectionviewcell

我有一个带有部分的集合视图,当用户单击一个单元格时,我正在尝试将其标记为已选中或已选中,然后对所选单元格做出反应,但我遇到的错误是: 每个部分有12个单元格,当我选择单元格时一切都很好我可以将其标记为已选中,但它也标记了另一个单元格,它每5个单元格标记一次单元格,如果我将每个单元格的单元格降级为5,则一切正常只有1个细胞。 这是我的代码:

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 12
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("videoCell", forIndexPath: indexPath) as! VideoCell
    return cell
}

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! VideoCell

    if cell.checked == true {
        cell.uncheck()
    }
    else {
        cell.check()
    }

}

0 个答案:

没有答案