0

I have a UITableView subclass that has the keyCommands property implemented, where there are several UIKeyCommands provided. This UITableView is a subview of the main view in the View Controller.

When I run the app and hold Command to preview the available keyboard shortcuts, those key commands do not show up.

I have tested this custom UITableView subclass in another project, and in a separate place in this project. In both cases, the table view belongs to a UITableViewController subclass instead of a plain UIViewController subclass, which I am using in this situation.

I tried to call becomeFirstResponder on the table view, but that did not make any difference.

Why are the table view's key commands not being recognized, and how can I fix this?

Jordan H
  • 52,571
  • 37
  • 201
  • 351
erdekhayser
  • 6,537
  • 2
  • 37
  • 69

1 Answers1

1

Apparently (I may be mistaken, but this is how it appears), the table view in UITableViewControllers has canBecomeFirstResponder return true, while the default value for UITableView is false.

To fix this, just add this method to the subclass:

override func canBecomeFirstResponder() -> Bool {
    return true
}
erdekhayser
  • 6,537
  • 2
  • 37
  • 69