I am creating a menu programmatically:
+ (void)refreshStatusMenu {
for (NSDictionary *dict in kbMsgSet) {
NSString *msj = [dict objectForKey:@"msj"];
NSString *mid = [dict objectForKey:@"mid"]; // <- this would be http://www.blah.com
msg_item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@", msj] action:@selector(goToURL:mid:) keyEquivalent:@""];
[msg_item setTarget:[self class]];
[sm insertItem:msg_item atIndex:(i_msg)];
i_msg++;
//...
}
}
How do I pass a parameter to @selector(goToURL:)
, so that on item-click I could call:
+ (void)goToURL:(id)obj {
NSLog(@"Open url:...%@", obj);
}
If I try passing @selector(goToURL:var2:)
I get uncaught exception error.
You can't have 2 parameters to an action method. There should only be one, the sender, which in this case would be the menu item. See the answer to this question for a way to attach extra information to a menu item and retrieve it in the action method.
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