Customised collectionView

来源:互联网 发布:nginx 压力测试 编辑:程序博客网 时间:2024/05/15 08:55

1. Construction

    var flowLayOut =UICollectionViewFlowLayout()

    var collectionView: UICollectionView?//must be optional


2. Setting

    Frequently-used properties for flowLayOut

        itemSize, minimumInteritemSpacing, minimumLineSpacing, scrollDirection


    collectionView = UICollectionView(frame: CGRect(...), collectionViewLayout: flowLayOut)

   Frequently-used methods for collectionView

        reloadData()

        deselectItemAtIndexPath()


3. Delegate

    UICollectionViewDataSource, 

    UICollectionViewDelegateFlowLayout


    funcnumberOfSectionsInCollectionView(collectionView:UICollectionView) -> Int {}

    func collectionView(collectionView:UICollectionView, numberOfItemsInSection section: Int) ->Int {}

    func collectionView(collectionView:UICollectionView, layout collectionViewLayout:UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) ->CGSize {}

    func collectionView(collectionView:UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) ->UICollectionViewCell {

    collectionView.registerClass(myCollectionViewCell.self, forCellWithReuseIdentifier: "myCell")

    var cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath)as? myCollectionViewCell

    }

    func collectionView(collectionView:UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {}


4. Nesting

    To nest a collectionView inside a collectionViewCell, do the exact same thing as if the collectionViewCell class is a VC. The only tricky part ispassing values between the "big" collectionView and the "small" collectionView. I use customised delegate (refer to another blog about customised delegate).

    



0 0