我有一个包含多种细胞类型的CollectionView。在不同单元格类型之间滚动时,性能可能会非常滞后。我不确定如何解决它。这是我的cellForItemAtIndexPath
:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if cellType == "imageCell" {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("iCell", forIndexPath: indexPath) as! ImageCell
//do things for cell
return cell
}else if cellType == "mapCell" {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("mCell", forIndexPath: indexPath) as! MapCollectionViewCell
//do things for cell
return cell
}else if cellType == "pCell" {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("pCell", forIndexPath: indexPath) as! PCell
//do things for cell
return cell
}else if cellType == "detailCell" {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("fCell", forIndexPath: indexPath) as! DetailCell
//do things for cell
return cell
}else{
return UICollectionViewCell()
}}