gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:34:04 24 4
gpt4 key购买 nike

我尝试将三个键盘快捷键添加到我的 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
}

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

关于ios - 为什么这三个 addKeyCommand 中只有两个起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33986948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com