·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> UICollectionViewController的创建

UICollectionViewController的创建

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

1. 在开发collection view的时候遇到的问题,因为页面在storyboard中,所以直接在storyboard里设置它的layout,和cell的size等属性。

2. 另外,UICollectionViewController控制器本来有四个init方法:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {}

- (id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout {}

- (id)initWithCoder:(NSCoder *)aDecoder {}

- (id)init {}

但是由于是在storyboard里直接定义的控制器,所以代码里只有initWithCoder:(NSCoder *)aDecoder 方法被调用,另外3个没有被调用。

3. 给它注册了定义的标题栏类MCMonthHeaderView, 没有使用xib文件.

[self.collectionView registerClass:[MCMonthHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"monthHeader"];

在MCMonthHeaderView类继承了UICollectionViewReusableView类,它的初始化方法也有三个,

- (id)initWithFrame:(CGRect)frame{} 

- (id)initWithCoder:(NSCoder *)aDecoder{}

- (id)init{}

发现只有initWithFrame:方法是被调用的,其他两个方法不会被调用.