2012-02-02 67 views
7

我有一个UITextView接收来自键盘的输入。 “自动启用返回键”复选框被选中,因此当UITextView为空时,返回键被禁用。如何手动启用或禁用键盘上的返回键?

我在键盘上方有一个表情符号栏,可以将表情符号添加到UITextView以下,但这是问题;当UITextView是空的,我加入表情符号到UITextView这样的:

[inputTextView insertText:@"\ue40d"]; 

那么ReturnKey仍然被禁用,虽然UITextView中的文本属性不为空。

我插入表情后尝试这样做:

[inputTextView setEnablesReturnKeyAutomatically:NO]; 

没有结果。它看起来像启用/禁用键盘的返回键只能通过键盘输入字符来触发。

任何想法的如何手动启用/禁用返回键?

+0

它是否工作打算,如果你输入普通的文本进去? – 2012-02-02 09:39:03

回答

2

这是一个黑客攻击的一位,但你可以尝试通过剪贴板而不是插入的文本:

UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; 

// Save a copy of the system pasteboard's items 
// so we can restore them later. 
NSArray* items = [generalPasteboard.items copy]; 

// Set the contents of the system pasteboard 
// to the text we wish to insert. 
generalPasteboard.string = text; 

// Tell this responder to paste the contents of the 
// system pasteboard at the current cursor location. 
[textfield paste: nil]; 

// Restore the system pasteboard to its original items. 
generalPasteboard.items = items; 

// Free the items array we copied earlier. 
[items release]; 
-1

取消选中“自动启用Return键”

+1

这使得它始终处于启用状态...... – GreenKiwi 2012-07-02 22:41:31