最初に私のコード:@selector
- (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
{
if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
NSMenu * m = [[NSMenu alloc] init];
if (item != nil) {
NSLog(@"%@",[item title]);
[m addItemWithTitle:[item title] action:@selector(press:) keyEquivalent:@""]; // problem. i want to give "item" as an argument.....
for (NSMenuItem* i in [m itemArray]) {
[i setTarget:self];
}
} else {
[m addItemWithTitle:@"clicked outside" action:nil keyEquivalent:@""];
}
return [m autorelease];
}
return nil;
}
-(void) press:(id)sender{
NSLog(@"PRESS");
}
私は、セレクタと私のpress:
メソッドに引数としてitem
を与えたいです。
はどうもありがとうございました:)
PS:私はマックではないiPhoneのためにこれをやっているし。
+1 whoops、私は 'item'が' NSMenuItem'と異なっていたことを忘れました。 –
ありがとうございました+1 – cocos2dbeginner