Skip navigation.
 
mlSubclassed NSTextField can't bind backgroundColor to NSCollectionViewItem
FROM : David Carlisle
DATE : Sat Dec 01 10:19:06 2007

I'm trying to simulate an NSTableView using an NSCollectionView 
because [[(NSTableView *)tv animator] reloadData] won't work.  I 
thought it would be more likely I could animate an NSCollectionView. 
I have at least one NSTextField in my CollectionViewItem NSView where 
I want to be able to control the background color.

Since the text of the NSTextField is bound in Interface Builder to the 
NSCollectionViewItem, I thought that to bind to the backgroundColor in 
my NSTextField subclass, I could put the following method in its 
initWithCoder method.  The "cvi" variable is an IBOutlet connected in 
IB to the NSCollectionViewItem.

[self bind: @"backgroundColor"
     toObject:cvi
    withKeyPath:@"representedObject.backgroundColor"
     options:nil];

The problem is that when NSTextField initWithCoder is called, cvi is 
nil.

Is there a workable approach? And is there a good reason why 
backgroundColor shouldn't be bindable in Interface Builder?

Related mailsAuthorDate
mlSubclassed NSTextField can't bind backgroundColor to NSCollectionViewItem David Carlisle Dec 1, 10:19
mlRe: Subclassed NSTextField can't bind backgroundColor to NSCollectionViewItem David Carlisle Dec 1, 20:16