2014-02-25 32 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'。 –