1

In IB I create a NSCollectionView and its NSCollectionViewItem and a NSView which belongs to NSCollectionViewItem.My NSCollectionItem consist of a NSImageView and a NSTextField.I set them values using cocoa bindings.I want to change the border color of NSImageView when NSCollectionItem is selected.I create their own classes for all of them and set their custom class in IB.In NSCollectionViewItem class I rewrite its setSelected:(BOOL)flag function.The code is

 - (void)setSelected:(BOOL)flag
{
   [super setSelected:flag];

   [[self view] setSelected:flag];
   [[self view] setNeedsDisplay:YES];
}

I want to change the border color when the NSView calls its draw function.In the NSView class I create IBOutlets of the NSImageView and NSTextField,connecting them with IB.But when the draw function is called , I use the code

if(selected){
    NSLog(@"self.imageView = %@",self.imageView);
}

The result is nil.Why I can't get the imageView of selected NSCollectionViewItem? Where I make the mistake? Help me ,thank you!

Muddu Patil
  • 713
  • 1
  • 11
  • 24
gohamgx
  • 273
  • 2
  • 16

1 Answers1

0

NSCollectionViewItem is the subclass of NSViewController.So,in ib,I connect the NSImageView of the NSView with the imageView of the NSCollectionViewItem and set the NSImageView's class to my own class which is subclass of NSImageView.In the draw function of the NSImageView,the result of NSLog is not nil and I can draw something of myself.

gohamgx
  • 273
  • 2
  • 16