我有一个applescript-objc脚本,它的方法如下:
on say_(phrase, userName)
set whatToSay to "\"" & phrase & " " & userName & "\""
say whatToSay
end say_我想从目标-c调用这个方法,但是我似乎不知道如何用多个参数调用方法,我没有问题只调用一个参数,如下所示:
@interface NSObject (ASHandlers)
- (void)say:(NSString *)phrase;
@end
@implementation AppDelegate
@synthesize window, sayTextField;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
scriptFile = NSClassFromString(@"Test");
if ( !scriptFile ){
// Handle errors here
return;
}
}
- (IBAction)say:(id)sender{
NSString *phrase = [sayTextField stringValue];
[scriptFile say:phrase];
}有人能帮忙吗。
你好,安迪。
发布于 2013-08-06 18:49:16
首先,IBActions必须具有以下签名:
-(void)action;
-(void)actionWithSender:(id)sender;
-(void)actionWithSender:(id)sender event:(UIEvent*)event;因此,如果您想要的是多个参数,那么您就不能拥有一个具有多参数的IBAction。
但是,要回答您的问题,在Objective中有一个具有多个参数的方法,如下所示:
- say:(NSString *)textToSay withUserName:(NSString *)userName {
...
}在AppleScriptObjC中,将所有Objective方法参数移到方法名称的开头,用下划线替换冒号,并将参数放在括号中。
on say_withUserName_(textToSay, userName)
...
end say_withUserName_ https://stackoverflow.com/questions/18016876
复制相似问题