I really apologize in advance for this question, but I am not fully understanding how tables work in an OSX app. What I'd like the user to be able to do is to select multiple rows in a single column table, and I'd like to know which rows were selected. The app populates the table, and the user cannot change it. I've been searching the web, SO, and I've cobbled together the following code, which is the controller for a single column table. I created a Table View in IB and wired its data source and delegate to File's Owner in IB. I now have a table with the array that I defined and can highlight the rows:
The controller code is as follows:
import Cocoa
class MainWindowController: NSWindowController {
let mylist = [ "worm", "pickle", "ladybug" ]
override var windowNibName: String {
return "MainWindowController"
}
override func windowDidLoad() {
super.windowDidLoad()
}
}
// NSTableViewDataSource
extension MainWindowController: NSTableViewDataSource {
func numberOfRowsInTableView( aTableView: NSTableView ) -> Int {
return mylist.count
}
func tableView( tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
var cellView: NSTableCellView = tableView.makeViewWithIdentifier( tableColumn!.identifier, owner: self ) as! NSTableCellView
cellView.textField!.stringValue = mylist[ row ]
return cellView
}
}
// NSTableViewDelegate
extension MainWindowController: NSTableViewDelegate {
}
What I don't understand is how to allow the user to select multiple rows and how to access which rows are selected. I have a feeling that I'm missing something simple, but I am just stumped. Any help would be very much appreciated.