开发者

How can I pass a parameter to a selector?

开发者 https://www.devze.com 2023-01-28 23:51 出处:网络
I have an NSSearchField: [searchField se开发者_StackOverflowtAction:@selector(doSearchWithQuery:)];

I have an NSSearchField:

[searchField se开发者_StackOverflowtAction:@selector(doSearchWithQuery:)];

Here is my doSearchQuery:

-(void)doSearchWithQuery:(NSString*)query{

How can I pass the contents of my searchfield into doSearchWithQuery?


You can't do exactly what you're describing. A selector doesn't do anything or accept any parameters — it's just the name of the message to send. You can only pass arguments when you actually send a message. However, controls always pass themselves as an argument to their actions, so what you need is a wrapper method along these lines:

- (void)doSearchFromSearchField:(NSSearchField *)sender {
    [self doSearchWithQuery:[sender stringValue]];
}

And set that as the action.

0

精彩评论

暂无评论...
验证码 换一张
取 消