Collectionview inside tableview cell with 1 data source

I want to put the collection in a tableview cell. Each tableview cell contains 2 collectionviewCell. Say I have 8 pic in my data model, I want the collection view to look like an image. How to do it?

enter image description here

+4
source share
1 answer

Instead of using Collection View inside a tableview, use only the vertical scroll view of the collection 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);
    }

This way you will have this look, just add a pad and you will get the results enter image description here

+1
source

All Articles