Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Fix returned array for UICollectionView header title (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis authored Oct 17, 2016
1 parent a410dc1 commit 96d0a49
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions Source/DATASource+UICollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ extension DATASource: UICollectionViewDataSource {

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cellIdentifier = self.cellIdentifier

if let value = self.delegate?.cellIdentifier?(forIndexPath: indexPath) {
cellIdentifier = value
}

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath)

self.configure(cell, indexPath: indexPath)
Expand All @@ -41,21 +41,15 @@ extension DATASource: UICollectionViewDataSource {
return view
}

if let title = title as? NSArray, title.count > 0 {
if let firstTitle = title[0] as? String {
if let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: DATASourceCollectionViewHeader.Identifier, for: indexPath) as? DATASourceCollectionViewHeader {
headerView.title = firstTitle
return headerView
}
}
if let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: DATASourceCollectionViewHeader.Identifier, for: indexPath) as? DATASourceCollectionViewHeader {
headerView.title = "\(title)"
return headerView
}
}

if let view = self.delegate?.dataSource?(self, collectionView: collectionView, viewForSupplementaryElementOfKind: kind, atIndexPath: indexPath, withTitle: nil) {
} else if let view = self.delegate?.dataSource?(self, collectionView: collectionView, viewForSupplementaryElementOfKind: kind, atIndexPath: indexPath, withTitle: nil) {
return view
}
fatalError("Couldn't find supplementary view for kind: \(kind) at indexPath: \(indexPath)")

fatalError("Couldn't find supplementary view for kind: \(kind) at indexPath: \(indexPath), if you don't expect any headers to be used, consider removing the `headerReferenceSize` from your UICollectionViewLayout.")
}

func cacheSectionNames(using keyPath: String) {
Expand All @@ -81,7 +75,7 @@ extension DATASource: UICollectionViewDataSource {

let objects = try! self.fetchedResultsController.managedObjectContext.fetch(request) as! [NSDictionary]
for object in objects {
self.cachedSectionNames.append(object.allValues)
self.cachedSectionNames.append(contentsOf: object.allValues)
}
}
}

0 comments on commit 96d0a49

Please sign in to comment.