Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
- Subject: Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
- From: Quincey Morris <email@hidden>
- Date: Mon, 03 Oct 2011 11:35:46 -0700
On Oct 3, 2011, at 01:36 , Gilles Celli wrote:
> As you suggested I tried the different options (putting a button cell in IB) and also returning with a non-nil cell for the NSOutlineView…but I'm not quite sure what you mean: Do I need to remove the "buttonColumn" and have only one column ? And then generate a NSButtonCell with an NSString generated from the OvItem name ?
NSOutlineView draws "cells" by going column by column in each row. For each such cell (that is, row/column combination), it gets a NSCell object, usually directly from the NSTableColumn but sometimes from the delegate method we've been discussing. The delegate method is called once for every row/column combination, to give it an opportunity to override the default NSCell that would otherwise be used.
Once it has the NSCell (well, it's a NSCell subclass, so that it can draw appropriately for text, a button, an image, etc), the outline view configures it to draw in the correct place within the view, and gives it the correct data to draw for the current row/column combination.
This means that all of the rows have the same layout. Using the delegate method, you can change what it displayed at each cell, but you still end up with the same rectangular, tabular pattern.
Except…
Before calling the delegate method once per column in a row, the outline view first calls it with a nil table column parameter. If the delegate method returns a non-nil NSCell, the outline view uses that call to draw the *entire* row, instead of going column by column.
If you think about it in your scenario, you'll realize that doing this on all non-detail rows will have the side-effect of suppressing the button on all non-detail rows, which is what you set out to do. It also makes your location and instrument label rows look a bit better (generally), because there's more room for longer names, and there are no weird blank gaps where the button would have been.
Also, if you follow this approach, you won't actually have to create any NSCells yourself. When your delegate method decides to return a whole-row cell, it can just use the one from the non-button column -- that is, after all, the cell that would have been used if you were drawing the row normally. In this case, the outline view will configure the cell to draw full width, so you don't need to worry about getting any geometry right.
I realize this sounds a little complicated initially, but once you realize how NSCells are used to break down drawing in table and outline views into a step-by-step process, you'll find it pretty easy to understand.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden