A selector is a method name. The action parameter needs to be the name of a method to be called when the item is selected; there is no method named "fileOrFolder".
ok... that makes sense...
i've managed to populate my NSMenu with items, but they are all disabled. i've added a selector, but they're still not selectable.
Code:
- (void)awakeFromNib
{
NSMenu *documentsMenu = [[NSMenu alloc] initWithTitle:@"Documents"];
NSMenuItem *documentsItem = [[NSMenuItem alloc] initWithTitle: @"" action: nil keyEquivalent: @""];
[documentsItem setSubmenu:documentsMenu];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [@"~/Documents" stringByExpandingTildeInPath];
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:documentsDirectory];
NSString *fileOrFolder;
while ((fileOrFolder = [directoryEnumerator nextObject]))
{
NSLog(fileOrFolder);
[directoryEnumerator skipDescendents];
NSMenuItem *documentsItem = [[NSMenuItem alloc] initWithTitle:fileOrFolder action:@selector(launchFileOrFolder:) keyEquivalent:@""];
[documentsMenu addItem:documentsItem];
[documentsItem release];
}
//"theMenu" is an IBOutlet to an NSMenu with 2 items already listed. i place documentsItem between those 2 items at index:1.
[theMenu insertItem:documentsItem atIndex:1];
[documentsMenu release];
[documentsItem release];
}
- (void)launchFileOrFolder
{
[NSApp terminate];
}
by the way, my selector is just for testing purposes here. the real method will tell a file to launch.
additionally, the title of the documentsMenu is not visible when it's added to theMenu. the menu will appear when it's selected but it's just not showing it's title "Documents" as it should.
i'm not adverse to learning, but this seems to be a fairly common task that developers would want to implement in their applications, but it seems like a very long difficult process... is there nothing that will do this automatically? maybe a feature in interface builder?