Sketch Plugin: How to dynamically update NSButton components (Objective-C, Cocoascript)

252 Views Asked by At

I am trying to develop a UI to get input for my sketch plugin. As far as I understand, Sketch allows us to write in JS, Cocoascript and Objective-C and eventually converts everything to Objective-C.

I am using the following code to generate the UI components like textbox and dropdowns. I am not sure how to connect them dynamically. For example, if I change the value of dropdown from a to b, I would like to disbale the textbox.

var pluginView = [[NSView alloc] initWithFrame: NSMakeRect(0,0,450,600)]

// Textbox
var ui_textbox = [[NSTextField alloc] initWithFrame: NSMakeRect(0,20,100,20)]
[ui_textbox setStringValue: "10"]
[pluginView addSubview: ui_textbox]

// dropdown
var ui_dropdown = [[NSComboBox alloc] initWithFrame: NSMakeRect(0,40,100,20)]
[ui_dropdown addItemWithObjectValue: "a"];
[ui_dropdown addItemWithObjectValue: "b"];
[ui_dropdown selectItemWithObjectValue: "a"];
[pluginView addSubview: ui_dropdown]

I am assumming that there should be a way to trigger a function when dropdown gets updated and in that function, I can manipulate the other UI parameters. I know how to manipulate the UI components. I am not able to figure out how to trigger the function onchange.

I already tried calling a function "ui_update" in the following ways

[rotateRelative setAction: "ui_update"];
[rotateRelative setAction: "ui_update:"]; 
[rotateRelative setAction: @selector"ui_update:"]; 

But no luck. That function does not get called.

any help will be super useful. Cheers!

0

There are 0 best solutions below