Search code examples
nstableviewnstablecellview

setObjectValue:nil not called to deleted NSTableCellView


I'm using a View Based NSTableView and binding to display content of my objects.

When I delete one of them, the tableView reflect the change, by removing the cell for this object.

The problem is that the NSTableCellView doesn't receive the setObjectValue: with nil or another object, and so the object referenceCount is not decremented, and my object never release.

Is there a way to override the tableView to force calling setObjectValue: when it cache deletedRows?

Thanks for your help.


Solution

  • I just found the solution right here.

    https://devforums.apple.com/message/575883#575883

    Just in case the link fail, the solution is to set it manually, in the following method

    - (void)tableView:(NSTableView *)tableView didRemoveRowView:(NSTableRowView *)rowView forRow:(NSInteger)row NS_AVAILABLE_MAC(10_7);
    {
        for (NSInteger columnIndex = 0; columnIndex < [rowView numberOfColumns]; columnIndex++) {
           [[rowView viewAtColumn:columnIndex] setObjectValue:nil];
        }
    }