When creating NSMenuItem your element must have a valid target and a valid selector. This means that the target cannot be zero and must respond to the transmitted selector. Keep in mind that in this case the NULL selector will not include the menu item.
NSMenu *myMenu; NSMenuItem *myItem; myMenu = [[NSMenu alloc] initWithTitle:@""]; myItem = [[NSMenuItem alloc] initWithTitle:@"Test" action:@selector(validSelector:) keyEquivalent:@""]; [myItem setTarget:myTarget]; [myMenu addItem:myItem];
EDIT: I saw that you call -[NSMenuItem setEnabled:] using YES after creating the menu item. This is optional since they will be enabled by default.
EDIT 2: As indicated by NSGod (see comment below), the target may be zero. In this case, the first responder of your application will receive the passed method. That is, until the first responder implements this method. (edit 3) However, if this is not the case, the method will be sent to the next responder in the responder chain. This continues until a defendant is detected that responds to the selector, or if there are no respondents remaining pending. When no responder is found, the menu item will not be included.
source share