Reputation: 987
I'm using RxSwift, I managed to create the dataSource and I retrieve cells correctly. Problem is with the section headerView. I have created a UICollectionReusableView class, attaching outlets from storyboard.
The problem is that I retrieve the view with collectionview.dequeueReusableSupplementaryView, but awakeFromNib is never called!
This is how I setup the collectionView
collectionView.register(UINib(nibName: "CardView", bundle: Bundle.main), forCellWithReuseIdentifier: "cardView")
collectionView.register(AddNewCardCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "AddNewCardCollectionHeaderView")
this is my UICollectionReusableView class
class AddNewCardCollectionHeaderView: UICollectionReusableView {
@IBOutlet weak var collectionViewRecommendations: UICollectionView!
@IBOutlet weak var viewWrapperRecommendations: UIView!
override func awakeFromNib() {
super.awakeFromNib()
}
}
And this is the dataSource
let dataSource = RxCollectionViewSectionedReloadDataSource<SectionOfItems>(configureCell: { (datasource, collectionview, indexPath, i) -> UICollectionViewCell in
let cell = collectionview.dequeueReusableCell(withReuseIdentifier: "cardView", for: indexPath) as! CardView
let card = self.getCard(atRow: indexPath.row, isCardRecommendation: false)
self.setCell(card:card,cell:cell)
return cell
}, configureSupplementaryView: { (datasource, collectionview, kind, indexPath) -> UICollectionReusableView in
let headerView = collectionview.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AddNewCardCollectionHeaderView", for: indexPath) as! AddNewCardCollectionHeaderView
return headerView
})
As awakeFromNib is not called, if I do for example headerView. viewWrapperRecommendations it will crash as nil, but I need to access to headerView outlets.
But, instead, awakeFromNib of CardView (the cell class) is called and it works perfectly.
Any help? Thanks!
Upvotes: 2
Views: 1465