我有三个键盘快捷键,我正在尝试添加到我的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键时,只有后两个被识别并显示在屏幕叠加层中。此外,只有第二个工作。
所有动作都已正确定义。建议将不胜感激。
答案 0 :(得分:2)
好的,我对此比较陌生,但我认为你做错了。而不是你正在做的事情,做到这一点。
在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
}
你的问题可能是你的函数中不正确的大写,或语法,或完全不同的东西!我希望这会对你有所帮助(对不起,这么晚)。