0

My application crashes when I create a custom NSTableHeaderCell for my NSTableView that does nothing except store a single optional of type NSFont. The table view draws fine the first time, but the app crashes when the table view is resized.

I have reduced the problem down to the presence of the NSFont optional.

class MyTableHeaderCell: NSTableHeaderCell {
    var myFont: NSFont?
}

I create a MyTableHeaderCell for each column in the table, e.g.,

        for (index, tc) in tableView.tableColumns.enumerated() {
            let v = MyTableHeaderCell(textCell:  "Title")
            v.myFont = NSFont.systemFont(ofSize: 14)
            tc.headerCell = v
        }

This likely has to do with the table view creating and destroying cells, but I am at a loss. If I simply use the font field of NSTableHeaderCell, the font gets changed back to the default after resizing the table view, hence the myFont field.

When the table view is resized, it appears that the value myFont gets trashed. Playing around with this, the app also crashes without even drawing the table view if I attempt to store a custom NSColor object instead of the NSFont.

Any ideas?

dcsalmon
  • 61
  • 5
  • I added some additional debugging and it appears that the table header for the last column in the table is getting copied and released over and over and that appears to be the source of the crash. None of the other column headers are ever copied. – dcsalmon May 02 '23 at 20:16
  • If I add an additional column to the table that does not have my custom header, everything works as expected. – dcsalmon May 02 '23 at 20:20

0 Answers0