NSTableView viewfor row, not working ?

Not sure I'm doing the right thing...

I have a NSSearchField and added a searchMenuTemplate consisting of NSMenu with NSMenuItem which works ok. Went a step further to add an NSTableView for the NSMenuItem's view which also seems to work ok. It consists of a NSTableView with an NSTableColumn as you can see below, after adding NSTableViewDataSource and NSTableViewDelegate I start running into a problem. The "numberOfRows" does work because I can see a size difference in the menu, however the "viewFor ... row" doesn't seem to be called, I know it returns nil and wouldn't worry about the state of the code it's just to show.



    weak var tableView: NSTableView!
   
    func numberOfRows(in tableView: NSTableView) -> Int {
       
        return 20
    }
   
    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
       
        let searchArray = ["Row 1","Row 2","Row 3","Row 4"]
        print(searchArray[row])
       
        return nil
    }
   
    func loadSearchBarMenu() {
       
        let tableView = NSTableView()
       
        let tableColumn = NSTableColumn()
        tableColumn.identifier = "tableColumnFirst"
        tableView.addTableColumn(tableColumn)
       
        tableView.delegate = self
        tableView.dataSource = self

You need to specify each column in the viewFor method.

Why do you add only first column in loadSearchBarMenu() ?

Not entirely sure how to do that.

I only want 1 column. What I was trying to do is a drop down list for recent searches that are cataloged and filter, a bit like on the IMDb website. Not sure of ways to make a selectable list on OSX. The recent searches is of NSSearchField, I'm still not sure what I'm doing with it but added a menu for the searchMenuTemplate and a menu item's view as the table.

You need to set a column name through Interface Builder.

I'm trying to create the whole object without the builder. Is it possible ?

NSTableView viewfor row, not working ?
 
 
Q