简体   繁体   English

带有1个数据源的tableview单元格内的Collectionview

[英]Collectionview inside tableview cell with 1 data source

I want to put collection view inside tableview cell. 我想将集合视图放在tableview单元格中。 Every tableview cell contains 2 collectionviewCell. 每个tableview单元格包含2个collectionviewCell。 Let say I have 8 pic in my data model, I want the collection view looks like the image. 假设我的数据模型中有8张图片,我希望集合视图看起来像图像。 How to do this? 这该怎么做?

在此输入图像描述

Instead Of Using Collection View inside tableview , Use only collection view with vertical scroll and in the method 而不是在tableview中使用集合视图,而是在方法中仅使用带有垂直滚动的集合视图

  #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 通过这种方式,您将拥有这样的视图,只需添加pading即可获得结果 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 tableview单元格内的Collectionview不会增加collectionView的高度 - Collectionview inside tableview cell not increasing height of collectionView collectionview在tableview单元格内重复 - collectionview are repeating inside a tableview cell 在 tableview 单元格内为 collectionview 加载更多功能 - Load more functionality for collectionview inside tableview cell tableview单元格索引路径内的Collectionview问题 - Collectionview inside tableview cell indexpath issue 单元重用tableview内collectionview中的另一个图像 - cell reuse another image in collectionview inside tableview 在 tableview 单元格内创建动态 collectionView - Create dynamic collectionView inside tableview cell 在tableview内的collectionview单元格的单击上导航 - navigate on click of collectionview cell inside tableview 单击CollectionView单元格时如何更新表视图数据(tableview.reloadData()在CollectionView的didSelectItemAt内部不起作用) - How to update table view data when a CollectionView Cell is clicked ( tableview.reloadData() not working inside CollectionView's didSelectItemAt ) 将目标添加到tableview单元格内的collectionview单元格的按钮 - Add target to button of collectionview cell inside tableview cell 在 TableView 内的 CollectionView 中填充动态数据 - Populating dynamic data in CollectionView which is inside TableView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM