Returning table view columns

First, let's supply the table with some details of how it should display its content, by providing it with table column views.

Add the following method to the NSTableViewDelegate extension:

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

We won't add the whole implementation of this method in one go; we'll start with the code for just the first table column.

Add the following code to the tableView(NSTableView, viewFor: row:) method:

if tableColumn == tableView.tableColumns[0] {   let cellIdentifier = "NameCellID"   var cell = tableView.make(withIdentifier: cellIdentifier,                             owner: self) as? NSTextField   if cell == nil   {  cell = NSTextField(frame: ...

Get Mastering macOS Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.