Skip navigation.
 
mlNSCollectionViewItem & Its View
FROM : I. Savant
DATE : Sun Nov 04 01:48:15 2007

List:

  I'm hoping someone can clarify something for me. I'm using the 
NSCollectionView/NSCollectionViewItem classes in a pet project of 
mine. The project is "garbage collection required". The item's 
designated view is a simple NSView subclass that has two properties 
defined as:

BOOL connected;
NSColor * statusColor;

  I dutifully initialized the statusColor and connected ivars in the 
view's -initWithFrame: method (to "NO" and "[NSColor redColor]", 
respectively). A strange thing happens, however, when -drawRect: is 
called. Most of my custom drawing shows up just fine (for the 
background) but the statusColor ivar is nil. Also, if I change the 
initialization to set the "connected" ivar to "YES", this value is 
ignored (it evaluates to "NO");

  I discovered -initWithFrame: is never called. Okay, so I moved the 
code to -awakeFromNib, which is called once, but I get the same 
results - my ivars appear uninitialized when used in -drawRect: ...

  My first suspicion was there was something about garbage collection 
that I do not understand but the view draws fine if I instantiate one 
of them in a separate window that stays on-screen. I've also been 
using GC in plenty of other classes with the exact same patterns. It's 
only happening when used by a collection view item.

  That lead me to suspect something is 'different' about how the 
collection view / item handles its views (since the "prototype view" 
theoretically is copied). Maybe it calls -init and not -initWithFrame: 
(odd, but worth a shot). Nope. Never called. Nor is -copy: ...

  I thought maybe the prototype view itself should just be a NSView. 
I enclosed all the controls in a subview and made *that* my subclass 
(turning the prototype view back into a stock NSView). No luck.

  The documentation is still rather sparse (I know Scott and mmalc, 
you guys had a lot to write for Leopard and detail will take time) so 
beyond the basics, I can't see any explanation for this behavior. I'm 
sure I'm missing something obvious but damned if I know what it is. 
Any ideas?

--
I.S.

Related mailsAuthorDate
mlNSCollectionViewItem & Its View I. Savant Nov 4, 01:48
mlRe: NSCollectionViewItem & Its View Doug Penny Nov 5, 16:57
mlRe: NSCollectionViewItem & Its View I. Savant Nov 5, 17:25