通常はバックグラウンドで(エージェントとして)動作する小さなココアアプリがあります。コンテキストメニューをポップアップできるようにしたい場合があります (現時点ではウィンドウや s.th. は表示されません)。
私はSnow Leopardのみをターゲットにしているので、これを試しました:
if (windows) {
NSMenu *theMenu = [[[NSMenu alloc] initWithTitle:@"test"] autorelease];
[theMenu setShowsStateColumn:NO];
[theMenu setAutoenablesItems:NO];
for (id item in windows) {
NSString *labelText = @"some text";
NSMenuItem *theMenuItem = [[[NSMenuItem alloc] initWithTitle:labelText
action:@selector(menuItemSelected:)
keyEquivalent:@""] autorelease];
[theMenuItem setTarget:self];
[theMenuItem setRepresentedObject:item];
[theMenuItem setEnabled:YES];
[theMenuItem setImage:icon];
[theMenu addItem:theMenuItem];
}
[theMenu popUpMenuPositioningItem:nil atLocation:[NSEvent mouseLocation] inView:nil];
}
メニューは完全にポップアップ表示されますが、項目にマウス カーソルを合わせると、項目が強調表示されず、クリックできません。
menuItemSelected: メソッドは次のようになります。
-(IBAction)menuItemSelected:(id)sender {
}
私が間違っていることは何か分かりますか?