I guess I'm living on the edge trying on OS X Yosemite to get a NSTableView to populate using JavaScript via the ScriptEditor. I can get the table to show up and number of rows are being set correctly however the actual data is not be loading in the table.
I do see this in the Console: 7/24/14 7:47:27.784 AM Script Editor[11708]: * Illegal NSTableView data source (). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:
However I think I have implemented the correct methods. Perhaps I'm missing something simple or perhaps there's a bug in the Javascript-Cocoa bindings. I see my log statements for numberOfRowsInTableView but never for objectValueForTableColumn.
Any ideas?
function makeTable() {
tableContainer = $.NSScrollView.alloc.initWithFrame($.NSMakeRect(10, 150, 380, 200));
tableView = $.NSTableView.alloc.initWithFrame($.NSMakeRect(0, 0, 364, 200));
column1 = $.NSTableColumn.alloc.initWithIdentifier("Col1");
column1.setWidth(252);
column1.headerCell.setStringValue("First Name");
column2 = $.NSTableColumn.alloc.initWithIdentifier("Col2");
column2.setWidth(198);
column2.headerCell.setStringValue("Last Name");
tableView.addTableColumn(column1);
tableView.addTableColumn(column2);
if($.MyDataSource==undefined) {
ObjC.registerSubclass({
name: "MyDataSource",
protocols: ["NSTableViewDataSource"],
methods: {
"numberOfRowsInTableView:": {
types: ["NSInteger"],
implementation: function() {
console.log("numberOfRowsInTableView called");
return 3;
}
},
"objectValueForTableColumn": {
types: ["id", ["NSTableColumn", "NSInteger"]],
implementation: function(col, row) {
console.log("objectValueForTableColumn called")
return "Scott"
}
}
}
});
}
tableDataSource = $.MyDataSource.alloc.init;
tableView.setDataSource(tableDataSource);
tableContainer.setDocumentView(tableView);
window.contentView.addSubview(tableContainer);
}