gpt4 book ai didi

objective-c - 如何手动启用或禁用键盘上的返回键?

转载 作者:可可西里 更新时间:2023-11-01 03:34:42 25 4
gpt4 key购买 nike

我有一个 UITextView 从键盘接收输入。选中“自动启用返回键”复选框,因此当 UITextView 为空时,返回键将被禁用。

我在键盘上方有一个表情符号栏,它也可以将表情符号添加到 UITextView,但问题就在这里;当 UITextView 为空时,我向 UITextView 添加了一个表情符号,如下所示:

[inputTextView insertText:@"\ue40d"];

然后 ReturnKey 仍然被禁用,尽管 UITextView 的文本属性不为空。

我在插入表情符号后试过这个:

[inputTextView setEnablesReturnKeyAutomatically:NO];

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

知道如何手动启用/禁用 Return 键吗?

最佳答案

这有点 hack,但您可以尝试通过粘贴板插入文本:

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];

关于objective-c - 如何手动启用或禁用键盘上的返回键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9109988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com