瀑布流是现在,APP开发的热点。它的出现,极大的让列表出现多种形态。不在是以前单纯的那个模式。今天,我们讲解怎么重新布局(也可以不用布局),和加载动态的HTML的数据,和数据的刷新,进行创建瀑布流。其实,有两种方法创建,但是,第一种,有点问题,但也是可以的。下面我们就开始进入主题:
第一步:我们首先创建 UICollectionView对象
#pragma mark 创建 CollectionView
-(void)makeCollectionView{
//实现瀑布流 ,我们要从新布局,那就要从新创建 UICollectionViewFlowLayout
// 创建一个布局的对象
ZSJ_PBL_CollectionViewFlowLayout * ZSJ_FlowLayout = [[ZSJ_PBL_CollectionViewFlowLayoutalloc]init];
//实现其代理
ZSJ_FlowLayout.delegate = self;
//创建UICollectionView的对象
_CollectView_zsj = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,64, self.view.frame.size.width,self.view.frame.size.height-108)collectionViewLayout:ZSJ_FlowLayout];
// 设置 UICollectionView 的一些属性
//两个代理
_CollectView_zsj.delegate =self;
_CollectView_zsj.dataSource =self;
//设置 UICollectionView的背景色
_CollectView_zsj.backgroundColor = [UIColorcolorWithRed:220/255.0green:220/255.0blue:220/255.0alpha:1];
// 注册 cell
[_CollectView_zsjregisterClass:[ZSJ_CollectionViewCellclass] forCellWithReuseIdentifier:CCELL_ID];
//将 UICollectionView添加到主视图控制器上
[self.viewaddSubview:_CollectView_zsj];
}
#pragma mark 实现 UICollectionView的代理方法
/**************************************************************/
//这个方法是处理 UICollectionView 返回 cell 的数量
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return_fashionModelArray.count;
}
/**************************************************************/
//这个是 UICollectionView 的 cell
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//创建 cell对象
ZSJ_CollectionViewCell * Cell = [collectionViewdequeueReusableCellWithReuseIdentifier: CCELL_ID forIndexPath:indexPath];
//可以传递数据
ZSJ_Modle * Model = _fashionModelArray[indexPath.row];
[Cell sourc:Model];
//实现收藏点击事件
[Cell.collectbuttonaddTarget:selfaction:@selector(collectClick:)forControlEvents:UIControlEventTouchUpInside];
//添加标记
Cell.collectbutton.tag = indexPath.row;
Cell.sharebutton.tag = indexPath.row;
//实现分享点击事件
[Cell.sharebuttonaddTarget:selfaction:@selector(shareClick:)forControlEvents:UIControlEventTouchUpInside];
//返回你定义好的Cell
return Cell;
}
/**************************************************************/
//这个是 UICollectionView cell被选中 触发的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}
/**************************************************************/
//这个方法是 UICollectionView是否可选择,即是 可否交互。
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
1、布局文件,声明的方法和属性
//
// ZSJ_PBL_CollectionViewFlowLayout.h
// 瀑布流_ZSJMeth
//
// Created by 周双建 on 15/12/9.
// Copyright © 2015年周双建. All rights reserved.
//
#import <UIKit/UIKit.h>