简体   繁体   中英

Reusing collectionView

I have VC and a collectionView inside of it. All the code that manages collection view i've putted in extension to that VC. But now i need to use this collection view inside another different VC, and i dont want to copy/paste this extension. I've tried to subclass UICollectionView, but it doest not call delegate/datasource methods inside. Here is signature of my extension:

func scrollViewDidEndDecelerating(scrollView: UIScrollView)
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize

and some private functions and properties. Where i should put all this methods, if i want to reuse them often?

You should put all of this logic into a separate VC and reuse the VC, you aren't just trying to reuse the collection view.

So, wherever you need a 'copy' of this collection view you would actually be adding a child VC and adding the view from the VC as a subview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM