0

I need to create a collectionView A contains few types of cells. One of the cell contains collectionView B that can scroll horizontally. So collectionView A will scroll vertically.

Can I know how to create it and how to display the data into collectionView B?

Thanks again guys

Kuldeep
  • 4,466
  • 8
  • 32
  • 59
kamenr
  • 95
  • 1
  • 13
  • Please have a look on it. https://stackoverflow.com/questions/45273765/collectionview-nested-inside-collectionview – aBilal17 May 07 '18 at 07:58
  • And this library may help you. https://www.cocoacontrols.com/controls/insights-for-instagram – aBilal17 May 07 '18 at 08:00
  • you mean like Appstore? Why not use `sections`. In `numberOfSections` and `numberOfItemsInSection`. – yveszenne May 07 '18 at 08:01
  • @aBilal17 will take a look bro..thanks – kamenr May 07 '18 at 08:02
  • @Haitus I think more like a Instagram, can created it with your way? – kamenr May 07 '18 at 08:02
  • @karenr, instagram, messenger, App Store that you scan swipe horizontal and vertical - Yes. Set like ... layout = UICollectionViewFlowLayout() layout.scrollDirection to either .vertical or horizontal – yveszenne May 07 '18 at 08:37
  • @Haitus is there any link or guide to check out? Because I am super new to swift and ios, thanks ya bro – kamenr May 07 '18 at 08:47
  • @karenr, Likewise, you could search in youtube the channel of lets build that app(I'm not endorsing) where he replicates App Store without storyboard. Or that library above, you could tweak it to your liking. Good luck :) – yveszenne May 07 '18 at 09:00

1 Answers1

0

Collection A have Cells lets call our target cell as ASubCell

then at ASubCell we will have Collection B with all of its delegate , and you will create delegate say ASubCellDelegate to send action on Collection B to ViewController of Collection A , here example

import UIKit

protocol ASubCellDelegate {
    // CollectionView Cell Pressed
    func onSubCellAtcolectionBPressed(_item : YourData)
}
class ASubCell: UICollectionViewCell {

    @IBOutlet weak var collectionViewB : UICollectionView!
     var delegate : ASubCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        // setup your Collection View B
    }

}


// set up your horizontal Collection View
extension UICollectionViewCell:UICollectionViewDelegate,UICollectionViewDataSource {
    public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
       let cell  =  collectionView.dequeueReusableCell(withReuseIdentifier: "YourBCellID", for: indexPath) as! YourBCellID
        return cell
    }
    public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        if delegate != nil {
            self.onSubCellAtcolectionBPressed(YourData)
        }
    }

}
Abdelahad Darwish
  • 5,969
  • 1
  • 17
  • 35
  • bro, I need to load all the data on the main view controller then display the data to both the collectionview A and B, not by clicking the cell. – kamenr May 07 '18 at 08:38
  • Yes you will Pass dataSource of collection be to cell of collection A , that what will done – Abdelahad Darwish May 07 '18 at 08:39