Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

important question #13

Open
yunyun1989114 opened this issue Jun 23, 2016 · 0 comments
Open

important question #13

yunyun1989114 opened this issue Jun 23, 2016 · 0 comments

Comments

@yunyun1989114
Copy link

viewForSupplementaryElementOfKind in collection view datasource function
but it is never be called
i want to know why

this is my source
override func viewDidLoad() {
super.viewDidLoad()
mCollectView.backgroundColor = UIColor.whiteColor()
mCollectView.dataSource = self
mCollectView.delegate = self
collectLayout.headerReferenceSize = CGSizeMake(mCollectView.frame.width, 100)
mCollectView.registerClass(UICollectionViewCell.classForCoder(), forCellWithReuseIdentifier: "cellID")
mCollectView.registerClass(YjiSectionHeader.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "MyHeader")
mCollectView.collectionViewLayout = collectLayout
}

@IBAction func changeMode(sender: AnyObject) {
    mCollectView.setCollectionViewLayout(collectLayout2, animated: true)
}

// section number
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 2
}

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

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cellID = "cellID"
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellID, forIndexPath: indexPath)
    cell.backgroundColor = UIColor.yellowColor()

    return cell
}


// ヘッダーを表示する
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
    var header : YjiSectionHeader? = nil
    if (kind == UICollectionElementKindSectionHeader) {
        header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "MyHeader", forIndexPath: indexPath) as? YjiSectionHeader
        if header == nil {
            header = YjiSectionHeader(frame: CGRectMake(0, 0, collectionView.frame.width, 50))

        }
    }
    return header!
}
// ヘッダーのサイズを設定する
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    return CGSize(width: collectionView.frame.width, height: 100)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant