- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我遇到了一个问题,即在键盘上按住删除键时,iOS 会向我的 UITextViewDelegate 提供不正确的信息。
当用户按住 iPad 上的 UITextView 上的删除键时,UITextView 将开始删除整个单词而不是单个字符,按住的时间越长(注意:这不会发生在模拟器)。
发生这种情况时,UITextView 委托(delegate)方法:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
使用包含正确光标位置但长度为 1 的范围进行调用。这是不正确的,因为 UITextView 现在正在删除整个单词,而不是单个字母。例如,下面的代码将只打印一个空格。
[textView substringWithRange:range]
string contains " "
尽管 UITextView 删除了整个单词。替换文本作为空字符串正确给出。有谁知道这个问题的解决方案或解决方法吗?
最佳答案
Jacob 提到我应该将此作为答案发布。所以就在这里。
我的变通方法是监控 shouldChangeTextInRange 中给定的文本长度和范围,然后将其与 textViewDidChange 中的文本长度进行比较。如果差异不同步,我会刷新我的支持文本缓冲区并从 TextView 中重建它。这不是最佳的。这是我的临时解决方法:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//Push the proposed edit to the underlying buffer
[self.editor.buffer changeTextInRange:range replacementText:text];
//lastTextLength is an NSUInteger recording the length that
//this proposed edit SHOULD make the text view have
lastTextLength = [textView.text length] + ([text length] - range.length);
return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
//Check if the lastTextLength and actual text length went out of sync
if( lastTextLength != [textView.text length] )
{
//Flush your internal buffer
[self.editor.buffer loadText:textView.text];
}
}
关于iphone - 按住退格键时的 UITextViewDelegate 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6007997/
我的 View Controller 变得越来越复杂,所以我决定将一些控件组合在一起并子类化一个 uiview。在我的 View Controller 中,我正在抓取 View : @property
我遇到了一个问题,即在键盘上按住删除键时,iOS 会向我的 UITextViewDelegate 提供不正确的信息。 当用户按住 iPad 上的 UITextView 上的删除键时,UITextVie
正在尝试为 UITextViewDelegate 和 UITextFieldDelegate 创建自定义委托(delegate)类。当我将这些类设置为它们自己的委托(delegate)时,或将另一个
我正在使用 swift 3,我有一个类如下: class Assistor : NSObject , UITextViewDelegate { private override init() { }
我有一个 UITableViewCell,我有一个评论 UITextView 来写评论。在写下评论时,我检查了 #hashtags 和 @mentions 以检查它们在应用程序服务器端的可用性并将它们
我正在尝试创建一个类,其唯一目的是实现 UITextViewDelegate,但由于某种原因,从未调用方法 shouldChangeTextInRange,这是我的代码: public class T
我正在尝试使用 UItextfields 委托(delegate)从 UITextField 动态更新 UITableViewCell,但它总是落后一个字符。 因此,如果我在 UITextView 中
当使用外部键盘时,我的 UITextView 会在我按下 Backspace 键(“向后删除”)时触发 shouldChangeTextInRange 消息,但如果我按下 Delete ( "forw
我一定是做错了什么,我的 UITextViewDelegate 实现方法没有触发。我有一个 UITextView,它是 UITableCellView 的 subview ,并且没有调用委托(dele
我正在尝试覆盖 textView shouldInteractWithURL 方法来处理可点击链接。所以我创建了一个继承自 UITextView 和 UITextViewDelegate 的子类,调用
我创建了一个带有可检测链接的 UITextView,但是我无法使用 UITextView 委托(delegate)函数“shouldinteractwithURL”。 我收到一条警告,指出该实例方法几
如何将 UITextView 的“委托(delegate)”导出连接到实现 UITextViewDelegate 协议(protocol)的类? 我似乎找不到例子in the docs 奇怪的是 UI
我是一名优秀的程序员,十分优秀!