Reputation: 91
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?
Upvotes: 7
Views: 2935
Reputation: 5115
You can use
textField.setValue(isEnabled, forKeyPath: "inputDelegate.returnKeyEnabled")
Fox example inside
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
Upvotes: 0
Reputation: 40995
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];
Upvotes: 2