关于集合视图UICollectionView
来源:互联网 发布:最流行编程语言 编辑:程序博客网 时间:2024/05/17 01:55
关于集合视图UICollectionView,现在应该是Apple主推的一个类,用的也越来越多,所以一定要像UITableView一样非常熟才行.下面详细述说我目前知道的东西.
//初始化UICollectionView
@interface RecommendView :UIView<UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,NetWorkRequestDelegate>
//系统给的样式,瀑布流
UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayoutalloc]init];
//设置横向(左右)滚动,默认是上下
layout.scrollDirection =UICollectionViewScrollDirectionVertical;
//设置大小
// layout.itemSize = CGSizeMake(100, 100);
// //行之距
// layout.minimumLineSpacing = 50;
// //列之距
// layout.minimumInteritemSpacing=50;
// //距离顶头
// layout.headerReferenceSize = CGSizeMake(100, 100);
// //距离结尾
// layout.footerReferenceSize = CGSizeMake(100, 100);
//把整个section往里缩了(上,左,下,右)
layout.sectionInset = UIEdgeInsetsMake(20,20,20,20);
//第一步,初始化创建集合视图对象
UICollectionView * _collectView = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,0,320,350)collectionViewLayout:layout];
//第二步,设置代理
_collectView.dataSource =self;
_collectView.delegate =self;
// 注册可重用视图的标示
[_collectViewregisterClass:[ProductCellclass]forCellWithReuseIdentifier:@"cell"];
[_collectViewregisterClass:[Samecat_RecommendCellclass]forCellWithReuseIdentifier:@"cell1"];
[_collectViewregisterClass:[PhotoSupplementaryViewclass] forSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"head"];
//定义展示的Section的个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 2;
}
//定义展示的UICollectionViewCell的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (section == 0) {
return [_dataAraycount];
}
return [_dataArray1count];
}
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(130,180);
}
//定义每个UICollectionView 的 margin(上,左,下,右)
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
returnUIEdgeInsetsMake(10,20,10,20);
}
//每个UICollectionView展示的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section ==0) {
_item = [_dataArayobjectAtIndex:indexPath.row];
static NSString * identIfer =@"cell";
ProductCell * cell = [collectionViewdequeueReusableCellWithReuseIdentifier:identIferforIndexPath:indexPath];
cell.item = _item;
return cell;
}
_item1 = [_dataArray1objectAtIndex:indexPath.row];
static NSString * identIfer =@"cell1";
Samecat_RecommendCell * cell1 = [collectionViewdequeueReusableCellWithReuseIdentifier:identIferforIndexPath:indexPath];
cell1.item = _item1;
return cell1;
}
//每个UICollectionView的section(区头)的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
return CGSizeMake(320,40);
}
//每个UICollectionView的section(区头)展示的内容
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
PhotoSupplementaryView * header = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"head"forIndexPath:indexPath];;
if (indexPath.section ==0) {
header.headerLabel.text =@"看过此商品的顾客最终购买";
}
if (indexPath.section ==1) {
header.headerLabel.text =@"同类产品热销";
}
return header;
}
//UICollectionView被选中时调用的方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- 关于集合视图UICollectionView
- UICollectionView 集合视图
- UICollectionView 集合视图详解
- UICollectionView 集合视图详解
- iOS8 UICollectionView 集合视图
- UICollectionView 集合视图
- 42.集合视图(UICollectionView)
- UICollectionView 集合视图
- 集合视图UICollectionView
- 集合视图 UICollectionView
- 52.集合视图UICollectionView
- UICollectionView-集合视图
- UICollectionView 集合视图 的使用
- OCiOS开发:集合视图 UICollectionView
- iOS开发 -- UICollectionView(集合视图)
- iOS开发:集合视图 UICollectionView
- iOS编程------集合视图UICollectionView
- 集合视图UICollectionView 介绍及其示例程序
- "无头单链表中删除节点"有感——变通 2014-03-18 17:56
- Java解析XML文档
- 用uboot 烧写uboot linux内核 文件系统到nandflash的 过程以及bootm go命令启动与区别
- hdu1251统计难题(字典树模版)
- Java 7之基础 - 强引用、弱引用、软引用、虚引用
- 关于集合视图UICollectionView
- Linux内核实现的双向链表(1)
- 基于 Apache 在本地配置多个虚拟主机
- 直接读取相册照片
- 使用jQuery自动跳转
- 【剑指offer】两个链表的第一个公共结点
- 字符设备驱动 架构分析
- 黑马程序员------毕老师视频笔记第七天------面向对象(final关键字)
- 如何编译Apache Hadoop2.2.0源代码