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 :

  1. how , if right way in terms of memory ?
  2. 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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -