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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.