How can I make a UIKeyCommand with the return/enter key?

隐身守侯 提交于 2019-12-03 23:35:13

问题


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

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):

// 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?


回答1:


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



来源:https://stackoverflow.com/questions/22027522/how-can-i-make-a-uikeycommand-with-the-return-enter-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!