[英]Swift Collection View With a Table View
在故事板中创建一个包含UICollectionView
(您已经完成)的原型单元格。 设置UIViewController
是dataSource
中的UICollectionView
,只是添加了所需的方法UICollectionView
。
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//return the array showing number of collectionViewCells in tableViewCell. Of course you will have to handle the data showed in each tableView cell, (maybe using collectionView tags or some other logic)
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
}
您只需要使用UICollectionView和customcell而不是UITableView。 例如,使用以下步骤输出。
1。 为collectionView定义datasourece方法。
2。 根据您的要求,在collectionView的布局委托方法下面放置并自定义
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(2, 2, 2, 2);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake([UIScreen mainScreen].bounds.size.width/4 - 30, 150);//you need to resize height and width as per your requirement.
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 10;
}
请查看以下链接。
“UITableViewCell内的UICollectionView”
教程介绍了如何在UITableViewCell中添加UICollectionView(For Horizontal Scrolling)。
希望这会有所帮助,干杯!!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.