views:

163

answers:

2

I've got an NSBrowser hooked up to an NSTreeController bound to an array of NSTreeNode objects. It's easy enough to get the text portion working by setting the Content and Content Value bindings to properly reference the tree controller, but how do I set the image for each cell using bindings?

+2  A: 

Unfortunately, you can’t easily do this with an NSBrowserCell. Use another cell for your browser columns, one which takes the object value passed to it in -setObjectValue: and populates its own text and image appropriately.

Ben Stiglitz
+2  A: 

There is no built-in mechanism for displaying an image in a browser cell using only bindings. You can rig such a system if you really want, but in my experience, sometimes it's more trouble than it's worth to jump through hoops just so you can say all your stuff uses bindings, and it's just easier to do things the old fashioned way.

The "traditional" method for putting an image in a browser cell is to implement the browser delegate method:

- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(NSInteger)row column:(NSInteger)column

This lets you customize the cell however you'd like before it gets drawn by the browser. Take a look at the SimpleBrowser example in /Developer/Examples/AppKit, and you'll find an example of how to use this delegate method there. You shouldn't need the custom cell that they use in that project though - the project hails back from the pre 10.2 days, before NSBrowserCell provided its own image drawing mechanism.

Brian Webster