NSTableView: dynamic columns

I need to display a tableView without knowing all of the columns at compile time.

The names, formats (and of course values) of some columns are given by a query during executing time.

 

So I thought I have to override the make function of tableView as follow:

override func make (withIdentifier identifier: String, owner: Any?) -> NSView? {

        if identifier != “ligne24” &&{ // “ligne24” is one of the identifier(s column I can’t build on compile time

            return super.make(withIdentifier: identifier, owner: owner)

        }

    

        let view = NSTableCellView()

        let txt = myNewTextField()

        txt.identifier = identifier

        view.subviews.append(txt)

    

        return view

    }

 

Of course, in another place of my code, I have added this:

column = NSTableColumn (identifier: “ligne24”)

column.title = “some title”

tableView.addTableColumn(column)

 

and in

func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?

I put the correct value in the textfield

 

at executing time, table is ok, I can see the column named ligne24, but this column is empty even if while debugging I ca see I put the correct value in the cell

 

Any Idea?

Powered by WPeMatico

About

You may also like...

Comments are closed.