1

I have a view based NSTableView where each row is NSView. When user clicks on any row it should have rounded corner and colour. I need to achieve something like -

enter image description here

Here trash is selected row. I found one solution here, But it is NSTableRowView Based solution, not NSView based. Thanks for your help.

Abhishek
  • 852
  • 9
  • 24

1 Answers1

0

Why is the NSTableRowView solution a problem? In view-based tables, each row consists of two main views:

  • An NSTableCellView. Since table views can have multiple columns, each row contains an NSTableCellView for each column in the table.
  • An NSTableRowView. This is displayed behind the NSTableCellViews for each row in the table. By default, this is the view which displays the blue background.

There's a good diagram showing this in Apple's documentation.

As such, creating your own NSTableRowView which draws the red/orange background would be a good way of achieving what you want as it sits behind the NSTableCellViews for the row. You can set these rows up and return them in the - tableView:rowViewForRow: NSTableViewDelegate method.

Alex Rozanski
  • 37,815
  • 10
  • 68
  • 69
  • Problem with NSTableRowView is that [reloadDataForRowIndex](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/#//apple_ref/occ/instm/NSTableView/reloadDataForRowIndexes:columnIndexes:) is not calling TableDelegate's rowViewForRow method. For NSTableRowView Based approach I have to do complete table reload(reloadData()). – Abhishek Aug 25 '15 at 07:00