nstableviewnstablerowview

NSTableView detect row scrolled off


I have a view-based NSTableView and each row has to generate some images which takes time. These are done on a background NSoperationQueue and started when a request for an image is made (through a binding).

When a row is scrolled off screen, if the NSOperation is still pending, I'd like to be able to cancel it, but I need to detect when a row is no longer visible. Should I be looking for the delloc on my CustomTableRowView, CustomTableCellView, or something else?

I guess I need the opposite of tableView:willDisplayCell:forTableColumn:row:

Some sort of tableView:willHideCell:forTableColumn:row:

Apple's TableView Playground has a comment:

// We would have to keep track of the block with an NSBlockOperation, if we wanted to later support cancelling operations that have scrolled offscreen and are no longer needed. That will be left as an exercise to the user.

I can cancel the operation, but I am not sure how to detect when a row is scrolled off.


Solution

  • I believe this is solved with

    tableView:didRemoveRowView:forRow:

    though I am not sure if it is called immediately after the row scrolls off or a short while later.