Customised collectionView

子车成和
2023-12-01

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


    func numberOfSectionsInCollectionView(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 is passing values between the "big" collectionView and the "small" collectionView. I use customised delegate (refer to another blog about customised delegate).

    



 类似资料:

相关阅读

相关文章

相关问答