I created a subclass of UICollectionReusableView. Then in the function
collectionViewTableLayoutManager(manager: collectionView: headerViewForRow row: indexPath: )
I am trying to dequeue a view and cast it to the subclass.
Here's the start of the method:
func collectionViewTableLayoutManager(manager: DRCollectionViewTableLayoutManager!, collectionView: UICollectionView!, headerViewForRow row: UInt, indexPath: NSIndexPath!) -> UICollectionReusableView! {
let view = collectionView.dequeueReusableSupplementaryViewOfKind(DRCollectionViewTableLayoutSupplementaryViewRowHeader, withReuseIdentifier: collectionViewHeaderIdentifier, forIndexPath: indexPath) as! CVHeaderView
It crashes at runtime on the "let view ... " with this error:
Could not cast value of type 'UICollectionReusableView' (0x103994fb8) to 'CollectionViewTableLayout.CVHeaderView' (0x1023f3bd0).
Here is my subclass code:
class CVHeaderView: UICollectionReusableView {
let textLabel: UILabel!
override init(frame: CGRect) {
let textSize = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)
textLabel = UILabel(frame: textSize)
super.init(frame: frame)
textLabel.font = UIFont.systemFontOfSize(10)
textLabel.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth
textLabel.textAlignment = NSTextAlignment.Center
textLabel.backgroundColor = UIColor.clearColor()
self.addSubview(textLabel)
}
required init(coder aDecoder: NSCoder) {
...
}
I'm confused why I can't do this downcast. Is it somehow related to my use of the outside library of the DR... classes?