UIViewController.AddKeyCommand(UIKeyCommand) Method

Definition

Adds command as a shortcut available to attached hardware keyboards.

[Foundation.Export("addKeyCommand:")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public virtual void AddKeyCommand (UIKit.UIKeyCommand command);
abstract member AddKeyCommand : UIKit.UIKeyCommand -> unit
override this.AddKeyCommand : UIKit.UIKeyCommand -> unit

Parameters

command
UIKeyCommand

Definition of the new keyboard action.

Attributes

Remarks

UIKeyCommand objects are only generated with an attached hardware keyboard.

To create keyboard accelerators, developers must create a Selector that is associated with a method of type Action<UIKeyCommand> with an appropriate ExportAttribute:

[Export("NewFileAccelerator:")]
void NewFileAccelerator(UIKeyCommand cmd)
{
   //etc...
}

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();

    var actionSelector = new Selector("NewFileAccelerator:");
    accelerator = UIKeyCommand.Create((NSString) "N", UIKeyModifierFlags.Command, actionSelector);

    AddKeyCommand(accelerator);
}

Applies to