Kodeco Forums

OS X NSTableView Tutorial

Table views are one of the most important OS X UI controls. Get up to speed with how to use them with this OS X NSTableView tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1455-os-x-nstableview-tutorial

As soon as I drag a checkbox into a column, the table changes to a cell based table instead of a view based table, which then wipes out all the data bindings I had set. How do I put a checkbox into a view based table and still use Cocoa Bindings?

First of all thank you for writing this tutorial!

I ran into a couple of minor issues along the way:

  1. The Status Label was being positioned outside of the window, I had to set a constraint to keep it in place.
  2. In the very last code snippet thereā€™s an extra ā€˜reloadFileList()ā€™ at the end of the tableView function.

Thanks for this great tutorial. There is a bug: currently you are returning creation date rather than modification date. Substituting NSURLContentModificationDateKey for NSURLCreationDateKey in public init( folderURL:NSURL ) seems to fix it (it has to be changed in the let declaration of requiredAttributes as well as in the date:properties assignment. Works for meā€“or you could change the column field to ā€œCreation Dateā€ if you prefer to show creation dates.

If you have an elegant way to change the dates to local with the short date format, Iā€™d love to see it.

This tutorial no longers works under xcode 8. These 2 statements are flagged as errors but were not previously.

tableView.setDelegate(self)   Value of type 'NSTableView' has no member 'setDelegate'
tableView.setDataSource(self)  Value of type 'NSTableView' has no member 'setDataSource'

Google does does not provide an answer as to what has changed and everything that I have tried does not work. Anyone have any ideas on how to fix this ? Maybe a Swift 3.0 issue ?

Based on Appleā€™s current documentation for NSTableView, I would use:

tableView.delegate = self
tableView.dataSource = self

Thanks that fixed it. Curious why this changed thoughā€¦ This project is one that I use for testing all new releases of Xcode that I install and it bothers me when things no longer work.

One of the proposals of Swift 3 was to make function arguments more consistent (in Swift 2 the first argumentā€™s treated a little differently to the others; in Swift 3 it isnā€™t). In this case the newer version mightā€™ve looked something like this:

tableView.setDelegate(delegate: self)
tableView.setDataSource(dataSource: self)

In Objective C, setting properties was an alias for the equivalent setProperty function. In Swift 3 it looks like theyā€™ve just decided to acknowledge properties and remove the setProperty equivalents. (Iā€™m speculating.)

This is a really good tutorial. Looking deeper into the starter project I see there is a lot of code you already had set up. It would be much appreciated if you could do a full tutorial, or go back and teach what you did prior.