如何将参数传递给选择器?
我有一个 NSSearchField:
[searchField setAction:@selector(doSearchWithQuery:)];
这是我的 doSearchQuery:
-(void)doSearchWithQuery:(NSString*)query{
如何将搜索字段的内容传递到 doSearchWithQuery 中?
I have an NSSearchField:
[searchField setAction:@selector(doSearchWithQuery:)];
Here is my doSearchQuery:
-(void)doSearchWithQuery:(NSString*)query{
How can I pass the contents of my searchfield into doSearchWithQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能完全按照你所描述的那样做。选择器不执行任何操作或接受任何参数 - 它只是要发送的消息的名称。您只能在实际发送消息时传递参数。但是,控件始终将自身作为其操作的参数传递,因此您需要的是一个遵循以下原则的包装方法:
并将其设置为操作。
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:
And set that as the action.