Custom NSTableHeaderCell crashes when the table is resized

35 views Asked by At

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?

0

There are 0 answers