首页 > 其他 > 详细

storyboard UICollectionView

时间:2017-01-12 08:10:39      阅读:215      评论:0      收藏:0      [点我收藏+]

场景:在开发中,在storyboard中创建一个UIViewController,又在上面拖进去了UICollectionView控件,这时想要使用自定义的cell和sectionHeader 并且不想单独创建子类的.xib文件

 

在storyboard外创建单元格和section头视图的子类(.h和.m),在stroyboard对应的cell和section的归属设为上一步创建的,并设置复用的identifier

 

使用的时候,不用再次注册单元格和复用的头尾视图,只用在对应的代理方法直接寻找就好了

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    

    NSString *sectionidentifier = NSStringFromClass([CollectionSectionCell class]);

    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {

        

        CollectionSectionCell *section = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:sectionidentifier forIndexPath:indexPath];

        return section;    //返回头视图

    }

    

    return nil;

}

 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    NSString *cellidentifier = NSStringFromClass([FavoriteCell class]);

    FavoriteCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellidentifier forIndexPath:indexPath];

    return cell;

}

storyboard UICollectionView

原文:http://www.cnblogs.com/binbins/p/6274468.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!