How to bind NSMenuItem state (enabled) to a specific NSNumber value?

How to bind NSMenuItem state (enabled) to a specific NSNumber value?

i.e.

if myNumber == 2, then my NSMenuItem should be included

I need to do this for several NSMenuItem:

i.e.

if myNumber = 3 then my second NSMenuItem should be included

thanks

+4
source share
3 answers

If you want to use a transformer, I think you will have to write it yourself, as in this example . It will register the class that defines the value transformer, which the system will then implement.

If you want to register an instance as a value converter, this document contains data. The advantage is that you can configure each instance differently without defining a class for each situation.

+1
source

Use IBOutlet for your NSButton and disconnect the entire button from the interface designer. then use the If else condition and enable your button.

 IBOutlet NSButton *my1;// Disable IBOutlet NSButton *my2; //Disable If(myNumber ==1) [my1 setState:NSOnState]; else If(myNumber ==2) [my1 setState:NSOnState]; 
0
source

you can bind its value (NSButton) in IB

-1
source

Source: https://habr.com/ru/post/1383856/


All Articles