2014-02-25 40 views
13

我想编一个仅使用[return]键的UIKeyCommand。到目前为止,我已经试过:如何使用return/enter键创建UIKeyCommand?

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

还有的回车键没有全局常量,像有对上,下,左,右,和逃生(从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); 

是还有什么我可以尝试捕获返回/输入密钥?

回答

24

使用@"\r"作为换行符而不是@"\n"应该起作用。

+0

你可能希望'\ r'超过'\ n'。 –