Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I manually enable or disable the Return Key on the keyboard?

I have a UITextView that receives input from the keyboard. The "Auto Enable Return Key" checkbox is checked, so when the UITextView is empty the Return key is disabled.

I have an Emoticons bar above the keyboard that can add emoticons to the UITextView as well, but here's the problem; When the UITextView is empty and I add an emoticon to the UITextView like this:

[inputTextView insertText:@"\ue40d"];

then the ReturnKey is still disabled, although the UITextView's text property is not empty.

I've tried this after inserting an emoticon:

[inputTextView setEnablesReturnKeyAutomatically:NO];

With no results. It looks like enabling/disabling the Return Key of the keyboard is only triggered by entering characters through the keyboard.

Any idea's how to do manually enable/disable the Return key?

like image 271
Bas Holtrop Avatar asked Feb 02 '12 09:02

Bas Holtrop


People also ask

How do I turn on the return button on my keyboard?

While on the ANSI keyboard, you can find the return key on the third row, above the right-hand Shift key and below the backslash \ key.

What is control Return on keyboard?

Almost all computer keyboards have a key marked Return or Enter; the two names are synonymous. The Return key moves the cursor (or insertion point) to the beginning of the next line. But more important, it returns control to whatever program is currently running.

How do I activate the return button on my Iphone?

Depending on the iOS version your device is running and your keyboard settings, the position of the Return key may vary. Sometimes, you may find it as soon as you launch the keyboard, but in a vast majority of cases, you'll be able to access it from the num pad section by tapping on the “123” key.


1 Answers

It's a bit of a hack, but you could try inserting the text via the pasteboard instead:

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];
like image 196
Nick Lockwood Avatar answered Nov 15 '22 07:11

Nick Lockwood