Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling custom selection style in view based NSTableView

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?

like image 692
edc1591 Avatar asked Dec 07 '22 18:12

edc1591


2 Answers

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.

like image 188
edc1591 Avatar answered Apr 01 '23 07:04

edc1591


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;
}
like image 39
fredzouille Avatar answered Apr 01 '23 07:04

fredzouille