为什么这三个 addKeyCommand 中只有两个起作用

Why do only two of these three addKeyCommand 's work

我尝试将三个键盘快捷键添加到我的 iPad 程序中。这是三个

        // add the "change Status" keyboard shortcut
    let statusShortcut = UIKeyCommand(input: "s", modifierFlags: UIKeyModifierFlags.Command, action: "changeStatusPressed:", discoverabilityTitle: "Change Status of Meeting")
    addKeyCommand(statusShortcut)

    // add the "add user" keyboard shortcut
    let addShortcut = UIKeyCommand(input: "+", modifierFlags: UIKeyModifierFlags.Command, action: "addButtonPressed:", discoverabilityTitle: "Add Participant to Meeting")
    addKeyCommand(addShortcut)

    // add the "remove user" keyboard shortcut
    let removeShortcut = UIKeyCommand(input: "-", modifierFlags: UIKeyModifierFlags.Command, action: "removeButtonPressed:", discoverabilityTitle: "Remove Participant to Meeting")
    addKeyCommand(removeShortcut)

当我按下键盘上的 Command 键时,只有后两个被识别并显示在屏幕覆盖中。另外,只有后两个有效。

所有操作都已正确定义。将不胜感激。

好的,我对此比较陌生,但我认为你做错了。做这个,而不是你正在做的事情。

在您的 ViewDidLoad 之后(在外部)执行所有这些操作:

override func canBecomeFirstResponder() -> Bool {
return true
}

override var keyCommands: [UIKeyCommand]? {
    return [

UIKeyCommand(input: "S", modifierFlags: .Command, action: "changeStatusPressed:", discoverabilityTitle: "Change Status of Meeting"),
UIKeyCommand(input: "+", modifierFlags: .Command, action: "addButtonPressed:", discoverabilityTitle: "Add Participant to Meeting"),
UIKeyCommand(input: "-", modifierFlags: .Command, action: "removeButtonPressed:", discoverabilityTitle: "Remove Participant from Meeting"),

   ]
}

func changeStatusPressed(sender: UIKeyCommand) {
    print("command-s selected")
    // code for changeStatusPressed
}

func addButtonPressed(sender: UIKeyCommand) {
    print("command+ selected")
    // code for addButtonPressed
}

func removeButtonPressed(sender: UIKeyCommand) {
    print("command- selected")
    // code for removeButtonPressed
}

您的问题可能出在您的函数或语法中大小写不当,或其他完全不同的地方!希望对您有所帮助(抱歉来晚了)。