绑定和 NSButton
使用绑定,如何使 NSButton 调用 AppDelegate 类中的方法?我尝试将目标选择器设置为 buttonClicked: 但在控制台中它给了我:
无法识别的选择器发送到实例 0x100105060
此外,绑定中没有地方指定在哪个实例中查找方法,那么如何将其设置为 AppDelegate?
谢谢。
Using bindings, how can I make NSButton invoke a method in my AppDelegate class? I tried setting the target sleector to buttonClicked: but in console it gives me:
unrecognized selector sent to instance
0x100105060
Also there's no place in bindings to specify which instance to look for the method in so how can I set it to AppDelegate?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如西蒙所说,绑定不适合这种情况。绑定允许您将 UI 元素“绑定”到数据源。在您的情况下,您需要采取行动 - 而不是绑定。
您收到错误是因为您尚未实际定义buttonClicked 操作。因此,请确保您使用类似于 AppDelegate.m 中的内容来声明它:
然后通过界面构建器设置操作,首先将“FilesOwner”设置为 AppDelegate,然后将 onTouchUpInside 事件连接到操作“buttonClicked”。
希望这有帮助!
As Simon says, bindings are not appropriate for this situation. Bindings allow you to "bind" UI elements to a data source. In your situation, you need an action - not a binding.
You are getting the error because you haven't actually defined the buttonClicked action. Thus, make sure you declare it with something like in your AppDelegate.m:
Then set the action via interface builder by first setting the "FilesOwner" to the AppDelegate and then connecting the onTouchUpInside event to the action "buttonClicked".
Hope this helps!
绑定用于同步变量和界面元素。
就您而言,我想采取行动会更好。使用
IBAction
声明您的方法,然后按住 Control 键将按钮拖动到 Interface Builder 中的 AppDelegate 实例,以便能够选择操作。Bindings are used to synchronize a variable and an element of the interface.
In your case, I guess an action would be better. Declare your method with
IBAction
and control-drag from your button to your AppDelegate instance in Interface Builder to be able to select the action.