cocoa - ValidateMenuItem is not getting called for NSMenuItem -
here sample class , usage:
@interface ccocoamenuitem : nsmenuitem { someclass *someobj; } - (void)menueventhandler:(id)target; - (void)setenableitem:(bool)nenabled; @end @implementation ccocoamenuitem - (bool)validatemenuitem:(nsmenuitem *)item { // return yes or no based on conditions; // method not getting called } @end ccocoamenuitem *dummyitem = [[ccocoamenuitem allocwithzone:[nsmenu menuzone]] initwithtitle:(nsstring*)astr action:nil keyequivalent:@""] autorelease]; [dummyitem setaction:@selector(menueventhandler:)]; [dummyitem settarget:dummyitem];
here validatemenuitem not getting called. have set action , target. target class object , have defined validatemenuitem in class only.
is there missing here?
in code you've posted, ccocoamenuitem
declares menueventhandler:
method in @interface
, doesn't implement it. menu items aren't validated if target doesn't respond selector you've set action
(such menu items disabled automatically).
btw, menuzone
meant nsmenu
, not nsmenuitem
.
Comments
Post a Comment