I have three keyboard shortcuts I am trying add to my iPad program. Here are the three
// 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)
only the second two are recognized and show up in the screen overlay when I press the Command key on the keyboard. Also, only the second two work.
All there's actions are defined correctly. Suggestions would be appreciated.
Ok, I am relatively new to this, but I think you are doing this wrong. Instead of what you're doing, do this.
Do all this after (outside) your 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
}
Your issue could have been anywhere from improper capitalization in your function, or syntax, or something completely different! I hope this helps you (sorry it's so late).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With