Coding a table view
Firstly, we need to start a new project. All we need here is the standard macOS template with which we started the project in Chapter 6, Cocoa Frameworks: The Backbone of Your App, so create that first.
Preparing the View Controller
Before we can get going on the code for the table view itself, we need to add a couple of properties to the View Controller that will manage the window in which that table view is built.
Add the following lines of code to the ViewController class:
class ViewController: NSViewController
{
var tableView: NSTableView!
var infoLabel:NSTextField!
} The table and label
We will create both of these UI elements without the aid of Interface Builder. This means we have three tasks to perform:
- Create an
NSTableView. - Configure that table view.
- Add an
NSTextFieldinfo label.
We'll create a method for each of those steps, but since they will only ever be used once, we will declare them within the scope of an umbrella function, buildUI. While it would be...