swiftmacosnstableview

Detect column drag or resize in NSTableView while it is happening in Swift


I am working with an NSTableView in a macOS application and am trying to keep an arrow image next to the header drag bar of the currently sorted column. I have successfully been able to place the arrow next to the drag bar, but it only updates its position when the drag is released. I need it to update its position while the column-drag/resize is happening.

I have tried using the tableView(_:mouseDraggedWith:), mouseDragged(with event: NSEvent) and tableView(_:didDrag:) delegate methods, but the mouseDragged functions don't trigger during column resizing, and the didDrag method triggers only upon mouse release.

I have also attempted to use the NSTableView.columnDidMoveNotification notification, but it also only triggers after the drag is released.

How can I detect the drag or resize of a column while it's happening, prior to the mouse click being released?


Solution

  • NSTableView has a method, setIndicatorImage(_:in:), that puts an image at the right end of a column header (where the sort indicator may be displayed).