How do I go about drawing my own custom selection style for a view based NSTableView
? I tried putting a BOOL
var in my NSTableCellView
subclass and set that to YES
if it is clicked and then I can successfully draw my custom selection. But how do I change that BOOL
var to NO
when another view is clicked? Thanks for any help.
EDIT: After reading through the NSTableView docs, it looks like I need to subclass NSTableRowView to override the selection drawing, but what do I do with my NSTableRowView subclass? How do I get the table to use it?
Alright, I figured it out. You just have to subclass NSTableRowView
. It has methods for drawing the background for selected and deselected rows. To get the table view to use your subclass just implement the table view delegate method tableView:rowViewForRow:
and return an instance of your subclass.
To make things clear, I think we should give the code of the delegate method :
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
{
MyNSTableRowView *rowView = [[MyNSTableRowView alloc]init];
return rowView;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With