I am working through a Cocoa in Swift book and I am stuck in a chapter on Bindings. The book uses nib files but I want to do everything programmatically (since I am joining a team that does not use nibs). The project is to create a view based table with 2 columns and the content of the table is bound to the arrangedObjects of an array controller. The array controller's content is bound to an array of Employee objects (Employee has 2 properties viz. name and salary).
I was able to create the table programmatically like below (one scroll view, one table view, 2 table columns):
let tableWidth = windowWidth! * 0.6
let tableHeight = windowHeight! * 0.8
scrollView = NSScrollView(frame: NSRect(x: windowWidth!*0.05, y: windowHeight!*0.08, width: tableWidth, height: tableHeight))
employeeTable = NSTableView(frame: NSRect(x: 0, y: 0, width: tableWidth, height: tableHeight))
employeeTable?.bind("content", toObject: (self.arrayController)!, withKeyPath: "arrangedObjects", options: nil)
nameColumn = NSTableColumn(identifier: "name column")
nameColumn?.width = tableWidth * 0.4
nameColumn?.headerCell.title = "Name"
raiseColumn = NSTableColumn(identifier: "raise column")
raiseColumn?.width = tableWidth * 0.6
raiseColumn?.headerCell.title = "Raise"
employeeTable?.addTableColumn(nameColumn!)
employeeTable?.addTableColumn(raiseColumn!)
employeeTable?.setDelegate(self)
scrollView?.documentView = employeeTable
As you can see, I have no clue if this table is Cell-based or View-based. How can I tell what my table is based on? Since the chapter is on Bindings, no delegate or data source methods are being used and I would like to do the same.
Next question: Like I said, the book uses NIBs and has ready access to the NSTableView, NSTableCellView and the NSTextField under it. First, the NSTableView's content was bound to the array controller's arrangedObjects. I was able to do this part programmatically since I created the tableView object myself in code. The book then binds the NSTextField's value to the NSTableCellView's objectValue.name (name is one of the Employee object's properties). How do I do this part since I did not create these NSTableCellView and NSTextField objects in my code? Is there a way to access them (assuming my table is even View-based)?