How to add headers programmatically to NSTableView

I have created programmatically a NSTableView with a couple of columns, this table view has 3 columns and I want to set headers for the columns to accomplish the same thing as you get when you selected headers in IB.

I looked for some examples, found a few things but not really work for me. How is this done. It seems like this should be easy to code.

This is an example of one of the examples I found.

         let headerCell = CustomTableHeaderCell.init(textCell: "123123")
//        let font = NSFont(name: "Arial", size: 22.0)
//        headerCell.stringValue = "firstname"
//        headerCell.font = font        self.tableView.tableColumns[0].headerCell = headerCell

But CustomTableHeaderCell is not found.

How is this done?

Answered by BigEagle in 725268022

I got the answer to this from apple support. It seems the tableView must part of a scrollView for the headers to appear.

So I removed any reference to the explicit creation of a table header view and I added the following code to get this working:

let scrollView = NSScrollView()
scrollView.documentView = tableViewForPrint
stackView.addArrangedSubview(scrollView)
Accepted Answer

I got the answer to this from apple support. It seems the tableView must part of a scrollView for the headers to appear.

So I removed any reference to the explicit creation of a table header view and I added the following code to get this working:

let scrollView = NSScrollView()
scrollView.documentView = tableViewForPrint
stackView.addArrangedSubview(scrollView)
How to add headers programmatically to NSTableView
 
 
Q