macoscocoamouseovernstablecellview

How to create table with highlighted-on-mouseover cells on macOS cocoa?


I'm trying to create a tray popover app with table very similar to the one Dropbox has in it's popover view. There is a table of files and when you hover mouse over a table cell, cell will highlight and show additional controls. I'm not sure if NSTableView is suitable for this at all? Does anyone have any advice?

Dropbox Popover Table WIth Highlighted Cell


Solution

  • This would be an ideal use of NSTableView. Using a view-based NSTableView, you'll be easily able to create the look of those cells (views). The highlight on mouse-over should be accomplishable if you add an NSTrackingArea to the table view (scroll view might be better) with -[NSView addTrackingArea:], which gives you callbacks for -mouseMoved: events. From that method you can use the locationInWindow property on the NSEvent, and then use NSTableView's -rowAtPoint: call to query which row you should change to display the hover event.