I have a question on how to use a selector with multiple parameters. I need to toggle this:
-(void开发者_StackOverflow)openBackupNamed:(NSString *)name
using this:
[backupList addItemWithTitle:file action:@selector(openBackupNamed:) keyEquivalent:@""];
I know that there is the withObject:
parameter for these cases, but I can't do this in the addItemWithTitle:action:keyEquivalent:
method or am I missing something?
Thanks
In your case you will have to create a new NSInvocation object and set it's index 2 parameter to your NSString (The 0- and 1-indexed parameters are reserved).
Example:
// Assuming:
NSString *myString = ...;
/* / */
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(openBackupNamed:)]];
[invocation setSelector:@selector(openBackupNamed:)];
[invocation setTarget:self];
[invocation setArgument:&myString atIndex: 2];
[invocation invoke]; // or use invokeWithTarget: instead of the above setTarget method.
Read the ADC NSInvocation Class Reference
Please mind the setArgument
message. You have to pass it the address of your parameter (your string), not the actual object itself.
精彩评论