Beginning Collection Views 路 Challenge: Enhance Section Headers | Ray Wenderlich

This is a companion discussion topic for the original entry at

After completing the exercise, I found that if I added a new item it would not update the count label in the section header. For those wondering how to fix this issue, I added the following code to the addItem function in MainViewController.swift file.

@IBAction func addItem() {
		let index = dataSource.indexPathForNewRandomPark()
		collectionView?.insertItems(at: [index])
        // Updates the count number in the section header, without fading animation
        UIView.performWithoutAnimation {
            collectionView.reloadSections(IndexSet(0 ..< dataSource.numberOfSections))

If you do not put the UIView.performWithoutAnimation, you would notice there is a fade animation when adding a new item. So depending on what you like, feel free to choose to do with it or without.

Just wanted to note that, in the following video when you subclass UICollectionViewLayout to enable the animation for adding an item. What I had suggested above with UIView.performWithoutAnimation{} will disable that.

After completing the exercise on subclassing UICollectionViewLayout, I鈥檓 still having an issue with eliminating the fading animation from using collectionView.reloadSections(IndexSet(0 鈥< dataSource.numberOfSections)).

Any suggestions on how to solve would be greatly appreciated.

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

This looks like a bug in the project. This is something we鈥檙e looking at and will update in the next version of the course.

Hi Brian, I鈥檝e got a quick question: Why not implement the Section class into DataSource, put the logic for Section objects into their own class and initialize new Section objects with a dedicated initializer, passing in the IndexPath from the (:viewForSupplementaryElementOf:at:) method?
I might be missing something here, but the approach in this video appears somewhat counterintuitive given the prior best practice advice to contain object logic within its own class.

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]