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

时间:2016-04-08 08:52:43

标签: ios swift uitableview uicollectionview

我想将集合视图放在tableview单元格中。每个tableview单元格包含2个collectionviewCell。假设我的数据模型中有8张图片,我希望集合视图看起来像图像。怎么做?

enter image description here

1 个答案:

答案 0 :(得分:1)

而不是在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);
    }

通过这种方式,您可以看到这样的视图,只需添加点文,即可获得结果enter image description here

相关问题