在 Mac OS 应用程序中使用控件

use of controls in Mac OS application

在视图中,有按钮、单选按钮和一些具有相同 IBAction 的按钮。我想知道点击了哪一个? 导致该操作的函数将 Sender 作为参数。 不幸的是,我不知道发件人的名字。 在其他语言中,如 Delphi,我们可以通过以下指令知道发送者的姓名:sender as Button).Name。 cocoa swift中有相同的吗?

您可能正在寻找 NSView.tag 属性:

An integer that you can use to identify view objects in your application.

您可以在代码中给您的控件一个标签:

yourControl.tag = 10

或故事板中:

然后您可以查看发件人的标签:

if sender.tag == 10 {
    // that's yourControl!
}