swift (3.3)UICollectionView 的 SectionHeader问题

来源:互联网 发布:excel怎样数据保护 编辑:程序博客网 时间:2024/06/05 06:02

(SectionHeaderView 不显示问题)
自己在写UICollectionView的时候 想设置SectionHeaderView的时候。怎么都不显示,layout 的布局也设置了,包括注册 sectionHeaderView

  collectionView.register(YMCollectionHeaderView.self, forSupplementaryViewOfKind:UICollectionElementKindSectionHeader, withReuseIdentifier: reusedId) // section headerView 的高        layout.headerReferenceSize = CGSize(width: SCREENW, height: 100);

最后发现一个版本的问题 , 因为比较懒,代理方法直接是copy的,但是swift3.3 的代理方法已经稍微变化,导致网上的方法不走。
网上方法:

   func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {        //判断如果 kind 是footerView类型        if kind == UICollectionElementKindSectionFooter {            //创建footerView, 填写footerView类型(kind)、复用标识符、indexPath            footerView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: reusedId, forIndexPath: indexPath)            //设置footerView背景颜色            footerView.backgroundColor = UIColor.redColor()            return footerView        }        return footerView    }

但是swift3.3 方法已经稍微不同,外部参数已经处理掉了

    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {        var reusableview:YMCollectionHeaderView!        if kind == UICollectionElementKindSectionHeader        {            reusableview = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: reusedId, for: indexPath) as! YMCollectionHeaderView        }        else if kind == UICollectionElementKindSectionFooter        {        }        return reusableview    }

在根据自己的一些要求来处理sectionHeaderView。

———–代码还是用心的好。
-谨记

原创粉丝点击