如何在Swift的UICollectionView上对相同的cell标识符应用不同的内容



这段代码对你来说有意义吗?我正试图将不同的内容放在同一单元格标识符上,这是在collectionView:didSelectItemAtIndexPath:上触发的:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    println("bosen kelima")
    if (collectionView == self.filterCollectionView) {//here
        println("First Content")
        let cell = self.filterCollectionView.dequeueReusableCellWithReuseIdentifier("FILTER_CELL", forIndexPath: indexPath) as! FilterThumbnailCell
        var filterThumbnail = self.filterThumbnails![indexPath.row] // this one through bottom of this function will be deleted and moved to "didSelectItemAtIndexPath"
        var filterThumbnailTwo = self.secondFilterThumbnails![indexPath.row]
        cell.filterTitle.text = filterThumbnail.filterName
        //Lazy Loading
            if filterThumbnail.filteredThumbnail != nil {
                cell.imageView.image = filterThumbnail.filteredThumbnail
            }
            else {
                cell.imageView.image = filterThumbnail.originalThumbnail
                //filterThumbnail is a class instance
                filterThumbnail.generateThumbnail({ (image) -> Void in
                    if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? FilterThumbnailCell {
                        cell.imageView.image = image
                    }
                })
            }
            if filterThumbnailTwo.filteredThumbnail != nil {
                cell.imageView.image = filterThumbnailTwo.filteredThumbnail
            }
            else  {
                cell.imageView.image = filterThumbnailTwo.originalThumbnail
                //filterThumbnail is a class instance
                filterThumbnailTwo.generateThumbnail({ (image) -> Void in
                    if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? FilterThumbnailCell {
                        cell.imageView.image = image
                    }
                })
            }

        return cell
    }
}
如果不明白,你能给我一个解决方案吗?我已经找了将近一个星期的解决方案,但仍然没有线索

哪些内容不同?

如果相同的Cell类型具有不同的状态,则需要Bool(2个状态)或enum(2个或更多状态)。

然后检查单元格的状态并执行所需操作。还需要根据需要从正确的对象更新单元格状态。

最新更新