Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 为什么不是';我的UICollectionViewCell是否正在更新?_Swift_Uicollectionview - Fatal编程技术网

Swift 为什么不是';我的UICollectionViewCell是否正在更新?

Swift 为什么不是';我的UICollectionViewCell是否正在更新?,swift,uicollectionview,Swift,Uicollectionview,我正在检查我的单元格的indexath在点击ti时是否可以被7整除。如果是,则该单元格应更改背景颜色。我相信我的代码是正确的,但什么都没有发生 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let cell: CollectionViewCell = collectionView.dequeueReusableCellWit

我正在检查我的单元格的indexath在点击ti时是否可以被7整除。如果是,则该单元格应更改背景颜色。我相信我的代码是正确的,但什么都没有发生

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超出范围