I am creating a status bar on my app and the menus show up fine, however it does not seem to access the actions that I have set up for it.
I am adding the status bar through a C function:
void MyFunction(CefRefPtr<CefBrowser> browser) {
MyMenuItem* item = [[MyMenuItem alloc] initWithTitle:@"Item 1" action:@selector(doAction:) keyEquivalent:@"")];
[item setBrowser:browser];
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
[menu setAutoenablesItems:NO];
[menu addItem:item];
NSStatusBar *statusBar = [NSStatusBar systemStatusBar];
MSStatusItem *statusItem = [statusBar statusItemWithLength:NSBariableStatusItemLength];
[statusItem retain];
[statusItem setImage:imageObj];
[statusItem setTitle:@"Status"];
[statusItem setHilightMode:YES];
[statusITem setMenu:menu];
}
Declaring the actions right above MyFunction():
@interfaceMyMenuItem : NSMenuItem {
CefRefPtr<CefBrowser>_browser;
}
@property (nonatomic) CefRefPtr<CefBrowser> browser;
- (void)doAction:(id)sender;
@end
@implementation MyMenuItem
@synthesize browser = _browser;
- (void)doAction:(id)sender {
NSLog(@"Doing action");
}
@end
Everything compiles just fine, So I think it might have something to do with creating the Items from a C function, but not properly setting up the interface.
have you tried setting target of menuitem and implementing validateUserInterfaceItem?
MyMenuItem* item = [[MyMenuItem alloc] initWithTitle:@"Item 1" action:@selector(doAction:) keyEquivalent:@"")];
[item setTarget:self];
and
-(BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem
{
return ([anItem selector] == @selector(doAction:));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With