1

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);
}
Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
Scott Walter
  • 9,426
  • 4
  • 18
  • 23

1 Answers1

0

Looks like i had the wrong method name for objectValueForTableColumn row:

ObjC.registerSubclass({
    name: "MyDataSource",
    protocols: ["NSTableViewDataSource"],
    methods: {
        "numberOfRowsInTableView:": {
            types: ["long", ["id"]],
            implementation: function(id) {
                console.log("numberOfRowsInTableView called", id);
                return 3;
            }
        },
        "tableView:objectValueForTableColumn:row:": {
            types: ["id", ["id", "id", "long"]],                    
            implementation: function(table, column, row) {
                console.log("objectValueForTableColumn called", table, column);
                return "Scott"
            }
        }                       
    }
}); 
Scott Walter
  • 9,426
  • 4
  • 18
  • 23