Aldo Lazuardi
Aldo Lazuardi

Reputation: 1948

Collectionview inside tableview cell with 1 data source

I want to put collection view inside tableview cell. Every tableview cell contains 2 collectionviewCell. Let say I have 8 pic in my data model, I want the collection view looks like the image. How to do this?

enter image description here

Upvotes: 4

Views: 655

Answers (1)

Himan Dhawan
Himan Dhawan

Reputation: 924

Instead Of Using Collection View inside tableview , Use only collection view with vertical scroll and in the method

  #pragma mark ------------Collection View Delegates-----------------
 override func numberOfSectionsInCollectionView(collectionView: 
        UICollectionView!) -> Int {
    return 1
}
   override func collectionView(collectionView: UICollectionView!, 
        numberOfItemsInSection section: Int) -> Int {
    return 4
}
    override func collectionView(collectionView: UICollectionView!, 
    cellForItemAtIndexPath indexPath: NSIndexPath!) -> 
         UICollectionViewCell! {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier,
         forIndexPath: indexPath) as !MyCollectionViewCell

    // Configure the cell
    let image = UIImage(named: Images[indexPath.row])
    cell.imageView.image = image

    return cell
}
   func collectionView(collectionView: UICollectionView,
    layout collectionViewLayout: UICollectionViewLayout,
    sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake(_collectionViewToAddImages.frame.size.width/2, _collectionViewToAddImages.frame.size.height/2);
    }

In this way you will have view like this, just add the pading and you will get the results enter image description here

Upvotes: 1

Related Questions