如何使用return / enter键创建UIKeyCommand?

时间:2022-08-23 23:02:42

I'd like to make a UIKeyCommand that uses only the [return] key. So far I've tried:

我想创建一个只使用[return]键的UIKeyCommand。到目前为止,我已经尝试过:

UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)];

There's no global constant for the enter key, like there is for up, down, left, right, and escape (from UIResponder.h):

输入键没有全局常量,例如up,down,left,right和escape(来自UIResponder.h):

// These are pre-defined constants for use with the input property of UIKeyCommand objects.
UIKIT_EXTERN NSString *const UIKeyInputUpArrow         NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputDownArrow       NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputLeftArrow       NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputRightArrow      NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputEscape          NS_AVAILABLE_IOS(7_0);

Is there anything else I could try to capture the return/enter key?

还有什么我可以尝试捕获return / enter键吗?

1 个解决方案

#1


26  

Using @"\r" for carriage return instead of @"\n" for newline should work.

使用@“\ r”进行回车而不是@“\ n”用于换行应该有效。

#1


26  

Using @"\r" for carriage return instead of @"\n" for newline should work.

使用@“\ r”进行回车而不是@“\ n”用于换行应该有效。