首先我的代码:
- (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");
}
我想用选择器item
作为我的press:
方法的参数。
非常感谢你 :)
PS:我是为 Mac 而不是 iPhone 做这个。