有关UICollectionviewController的一些问题
2016-06-22 16:06
344 查看
一般我们使用UICollectionView 会直接使用UICollectionview,初始化传入一个flowLayout(可以是UICollectionviewFlowLayout ,也可以是自定义布局)
如果你在自定义使用自定义的UICollectionviewController 。用来做引导页,做collection view的转场动画,等等。
你在viewDidLoad中按往常的写法,使用自定义的布局来初始化uicollectionview。会报错:错误信息UICollectionView must be initialized with a non-nil layout parameter'
意思明显是需要一个layout对象来初始化,但是在viewdidload 中有使用自定义的布局了
WaterFlowLayout *flowLayout = [[WaterFlowLayout alloc] init];
flowLayout.delegate = self;
collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];
collection.backgroundColor = [UIColor whiteColor];
collection.delegate=self;
collection.dataSource=self;
[collection registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
[self.view addSubview: self.collectionView];
其实在自定义的UICollectionviewController中 初始化就需要传入一个 layout 参数。。
当我们使用[[UICollectionViewController alloc] init];初始化操作时 就需要带入自定义的flow layout
可以在自定义的.m 中重写init方法,类似
- (instancetype)init
{
WaterFlowLayout *flowLayout = [[WaterFlowLayout alloc] init];
flowLayout.delegate = self;
return [super initWithCollectionViewLayout:flowLayout];
}
这样创建就可以带上自带的布局样式了,此外 需要将self.collectionview 设置为当前显示的collection view。
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; UICollectionView *collection = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
如果你在自定义使用自定义的UICollectionviewController 。用来做引导页,做collection view的转场动画,等等。
你在viewDidLoad中按往常的写法,使用自定义的布局来初始化uicollectionview。会报错:错误信息UICollectionView must be initialized with a non-nil layout parameter'
意思明显是需要一个layout对象来初始化,但是在viewdidload 中有使用自定义的布局了
WaterFlowLayout *flowLayout = [[WaterFlowLayout alloc] init];
flowLayout.delegate = self;
collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];
collection.backgroundColor = [UIColor whiteColor];
collection.delegate=self;
collection.dataSource=self;
[collection registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
[self.view addSubview: self.collectionView];
其实在自定义的UICollectionviewController中 初始化就需要传入一个 layout 参数。。
当我们使用[[UICollectionViewController alloc] init];初始化操作时 就需要带入自定义的flow layout
可以在自定义的.m 中重写init方法,类似
- (instancetype)init
{
WaterFlowLayout *flowLayout = [[WaterFlowLayout alloc] init];
flowLayout.delegate = self;
return [super initWithCollectionViewLayout:flowLayout];
}
这样创建就可以带上自带的布局样式了,此外 需要将self.collectionview 设置为当前显示的collection view。
相关文章推荐
- Android布局的小窍门?
- Web布局连载——两栏固定布局(五)
- 样式表CSS布局经验
- 在winform下实现左右布局多窗口界面的方法之续篇
- css网页布局中注意的几个问题小结
- DL.DT.DD实现左右的布局简单例子第1/2页
- 使用CSS框架布局的缺点和优点小结
- div+CSS网页布局的意义与副作用原因小结第1/2页
- 在winform下实现左右布局多窗口界面的方法
- Android布局技巧之创建可重用的UI组件
- Android编程之代码创建布局实例分析
- CSS顶级技巧大放送,div+css布局必知
- 用div实现像table一样的布局方法
- Bootstrap三种表单布局的使用方法
- 精彩的Bootstrap案例分享 重点在注释!(选项卡、栅格布局)
- 第七篇Bootstrap表单布局实例代码详解(三种表单布局)
- jQuery EasyUi实战教程之布局篇
- jQuery EasyUI 布局之动态添加tabs标签页
- jquery自适应布局的简单实例
- Bootstrap页面布局基础知识全面解析