-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make it work with NSTableViewDataSource? #8
Comments
@onmyway133 If I had to guess, your problem is in the line: return this.items.length
|
@matt-curtis thanks for reply Even if I change to |
Did you check to make sure your delegates were being retained? Try EDIT: I just did my own testing and confirmed it - your delegate/datasource is being released. Try assigning them to your |
@matt-curtis thanks I just changed the code to var manager = {
delegateClass: new MochaJSDelegate(),
delegate: null,
dataSourceClass: new MochaJSDelegate(),
dataSource: null,
items: ["one", "two", "three"],
setup: function() {
this.dataSourceClass.setHandlerForSelector("numberOfRowsInTableView:", function(tableView) {
log("hello")
return 10
})
this.dataSourceClass.setHandlerForSelector("tableView:objectValueForTableColumn:row:", function(tableView, column, row) {
log("world")
return "hello"
})
this.delegate = this.delegateClass.getClassInstance()
this.dataSource = this.dataSourceClass.getClassInstance()
}
} So after |
I don't think this is a problem with MochaJSDelegate. I seems like a problem with how your configuring your |
@matt-curtis Hi, if I change from tableView.dataSource = manager.dataSource
tableView.delegate = manager.delegate to tableView.setDataSource(manager.dataSource)
tableView.setDelegate(manager.delegate) Then it crashes. I think it can recognizes the dataSource now, but crash for some reasons
If I disable dataSource, and keep the delegate //tableView.setDataSource(manager.dataSource)
tableView.setDelegate(manager.delegate) then it works this.delegateClass.setHandlerForSelector("tableView:didClickTableColumn:", function(tableView, column) {
log("did click column")
}) Is that because |
I think we can create a Cocoa framework and load it from Sketch, but this is more challenging |
With this.dataSourceClass.setHandlerForSelector("numberOfRowsInTableView:", function(tableView) {
log("numberOfRowsInTableView")
return 2
})
this.dataSourceClass.setHandlerForSelector("tableView:objectValueForTableColumn:row:", function(tableView, column, row) {
log("objectValueForTableColumn")
return "hello"
}) I get the logs before it crashes. So the
I think it has to do with NSTableView cell based configuration |
This looks like a bug with how Mocha hands over return values to Objective-C to me (somewhere around here), to be honest. I think I've I've seen this bug before, but I can't recall where exactly. Your best bet is probably to try the framework route. I think Mocha may also not like the fact that the method expects |
@matt-curtis thanks for your help |
@matt-curtis Hi, so I went with the Cocoa framework approach. It is much much easier to test, debug within a Cocoa app, you can check it out https://github.com/onmyway133/Sketch-Action Have no idea why Sketch chose to use CocoaScript for plugin development, hope that it is not about the syntax, it does not worth it 😓 |
Nice work! Starred. 🌟 |
Hi, I'm trying to make it work with
NSTableViewDataSource
here https://github.com/onmyway133/Sketch-Action/blob/master/SketchAction.sketchplugin/Contents/Sketch/ui.js#L13but the callback is not called. I must be doing something wrong. Thanks
The text was updated successfully, but these errors were encountered: