I have an NSCollectionView that displays a bunch of items that are called "ImageCollectionViewItem"s. I have an ImageCollectionViewItem.xib file that solely has an NSView that covers the item. I want to be able to dynamically change what is in that view, but when I try to reference it, it is nil. I already checked questions like: outlets in UIViewController nil in viewdidload , that is not my problem, I linked it and I have the filled circle
Here is the viewcontroller extension:
extension ViewController : NSCollectionViewDataSource {
func collectionView(collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return titles.count
}
func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItemWithIdentifier("ImageCollectionViewItem", forIndexPath: indexPath) as! ImageCollectionViewItem
//This is what is nil:
let thisView = item.iconView
return item
}
}
And then here is the ImageViewCollectionItem code
class ImageCollectionViewItem: NSCollectionViewItem {
@IBOutlet weak var iconView: NSView!
var numItem: Int?
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.whiteColor().CGColor
}
}