I am trying to setup an NSCollectionView that has custom drawing in the individual NSCollectionViewItem views. I have an image that I need to draw in each view, but I cannot link the view back to the NSCollectionViewItem subclass in Interface Builder. Is there an init method I can use with my NSCollectionViewItem in order to perform initialization operations? I tried to implement copyWithZone, but I was doing something wrong because I got some eternal loop. Currently, the only opportunity I have found to make my connections to the view are after the selection has changed using -(void)setSelected:(BOOL)flag. I want to do my drawing in the view, but I need an image from my representedObject as my source. Everything I read that is NSCollectionView related, is seemingly incomplete.
@implementation CollectionViewItem
-(void)setSelected:(BOOL)flag {
[super setSelected:flag];
NSLog(@"setSelected: %d", flag);
// tell the view that it has been selected
[(CollectionViewItemView* )[self view] setSelected:flag];
// This is where I pass my image to my view
[(CollectionViewItemView* )[self view] setOriginalSprite:[(MyModel* )self.representedObject imageSource]];
[(CollectionViewItemView* )[self view] setNeedsDisplay:YES];
}
@end