Search code examples
macoscocoaxcode5.1nspopupbutton

Notification when NSPopupButton changes its value in cocoa XCode5


I want to know if is it a method different to

-(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item

and

-(void)menuDidClose:(NSMenu *)menu

to help me to know when NSPopupButton's selected value changes (for example by pressing a key name instead of selecting it from the NSMenu)


Solution

  • first create your IBAction:

    - (IBAction)mySelector:(id)sender {
        NSLog(@"My NSPopupButton selected value is: %@", [(NSPopUpButton *) sender titleOfSelectedItem]);
    }
    

    and then assign your IBAction to your NSPopupButton

        [popupbutton setAction:@selector(mySelector:)];
        [popupbutton setTarget:self];