swift - Multiple cells for a single UICollectionView -
in collection view, cell class must have different appearance different kinds of data in array.
i looking way create multiple cells , choose different 1 according input data, example :
internal func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { let cell1 = collectionview.dequeuereusablecell.. as! kind1 let cell2 = collectionview.dequeuereusablecell.. as! kind2 // here choose different 1 each kind of data return cell1 }
i trying understand if :
- how , if right way in terms of memory ?
- is design? how go making different layout of single cell? ( creating views , hiding them seems bad approach)
you need this
internal func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { if (data.kind == kind1) { let cell1 = collectionview.dequeuereusablecell.. as! kind1 return cell1 } else { let cell2 = collectionview.dequeuereusablecell.. as! kind2 return cell2 } }
by checking type of data can determine cell.
Comments
Post a Comment