Swift 为什么不是';我的UICollectionViewCell是否正在更新?
我正在检查我的单元格的indexath在点击ti时是否可以被7整除。如果是,则该单元格应更改背景颜色。我相信我的代码是正确的,但什么都没有发生Swift 为什么不是';我的UICollectionViewCell是否正在更新?,swift,uicollectionview,Swift,Uicollectionview,我正在检查我的单元格的indexath在点击ti时是否可以被7整除。如果是,则该单元格应更改背景颜色。我相信我的代码是正确的,但什么都没有发生 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let cell: CollectionViewCell = collectionView.dequeueReusableCellWit
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell: CollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
if (indexPath.row + 1) % 7 == 0 {
print("true")
cell.backgroundColor = UIColor(red: 70/255, green: 133/255, blue: 211/255, alpha:1.0)
}
}
我得到了真实的信息,但手机没有更新。你知道为什么吗?你不应该让另一个单元格出列就像是问一个新的单元格,只需使用
func cellForItemAtIndexPath(indexPath:NSIndexPath)->UICollectionViewCell?
参数索引指定节和 单元格的项目编号
返回位于 对应的索引路径,如果单元格不可见或 indexPath超出范围
您不应该让另一个单元格出列,就像询问一个新的单元格一样,只需使用
func cellForItemAtIndexPath(indexPath:NSIndexPath)->UICollectionViewCell?
参数索引指定节和 单元格的项目编号
返回位于 对应的索引路径,如果单元格不可见或 indexPath超出范围