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"]
        return nil
    func loadSearchBarMenu() {
        let tableView = NSTableView()
        let tableColumn = NSTableColumn()
        tableColumn.identifier = "tableColumnFirst"
        tableView.delegate = self
        tableView.dataSource = self

Powered by WPeMatico

You may also like...

Comments are closed.