[英]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.