Re: Drawing the background of a single row in NSTableView
Re: Drawing the background of a single row in NSTableView
- Subject: Re: Drawing the background of a single row in NSTableView
- From: Graham Cox <email@hidden>
- Date: Thu, 2 Jul 2009 11:40:21 +1000
On 02/07/2009, at 10:09 AM, Peter Zegelin wrote:
Problem with this is there is no obvious concordance ( that I can
see) between a row and its rectangle.
Wouldn't scrolling affect all this?
I wonder if the delegate method:
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn *)aTableColumnrow:(NSInteger)rowIndex
would be better for your needs? It gives you the row and column so you
know where you are, and is called as part of the drawing loop of the
table, you can just go ahead and draw. Use -rectOfRow to get the row
and paint the background. I just tried the code below and it works fine:
if( rowIndex == 5 && [[aTableView tableColumns] objectAtIndex:0] ==
aTableColumn )
{
NSRect rowRect = [aTableView rectOfRow:rowIndex];
[[NSColor lightGrayColor] set];
NSRectFill( rowRect );
}
Note that here I paint the background of row 5 and only for the first
column (though the whole row is painted - if you don't do this the
additional paints on columns > 1 will erase the content of the cells
in earlier columns. This shows that the table drawing is performed as
you'd expect: for each row draw columns 0..n). Some variation on this
ought to work for you.
Another alternative is to subclass NSTableView and override -
drawRow:clipRect: which might be considered less of a hack than using
the delegate method to draw.
--Graham
_______________________________________________
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