4

In code I have something like this:

let scrollView = NSScrollView()
let tableView = NSTableView()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do view setup here.

    tableView.delegate = self
    tableView.dataSource = self
    tableView.headerView = nil

    scrollView.documentView = tableView
    scrollView.hasVerticalScroller = true

    self.view.addSubview(scrollView)

}

Both required methods (numberOfRows and from the title) are declared. TableView is visible in view, scrollable and selectable. tableViewSelectionDidChange works properly, I can get index of selected row by tableView.selectedRow. But all cells are empty, because tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) called for none of the cells. I think, the problem is that tableView can't figure out which of the cells are visible right now. But I don't know what I should do with that

1 Answers1

10

Well, I struggled for a moment, but it became clear quickly. The tableView generated by you is fine.

The only thing that is missing is a column. You can simply add one column:

tableView.addTableColumn(NSTableColumn(identifier: "Column"))

Table Views display their views inside columns. Most tableViews have only one column and with the header hidden, we forget that they even exist.

Without any column, everything else works still normally. BackgroundRows load and selection works - which made me get to this solution.

mangerlahn
  • 4,746
  • 2
  • 26
  • 50
  • maybe, you can help me with another, but related question, http://stackoverflow.com/questions/40688353/what-replacement-for-uitableviewautomaticdimension-should-i-use-to-get-the-same – Роман Елизаров Nov 19 '16 at 01:40