【问题标题】:Toggle autocorrectionType on and off (UITextView)打开和关闭自动更正类型 (UITextView)
【发布时间】:2013-11-19 16:50:30
【问题描述】:

我有一个 UITextView,我希望能够为其切换 autocorrectionType。

像这样简单地切换 autocorrectionType 是行不通的。

myTextView.autocorrectionType = UITextAutocorrectionTypeYes;
myTextView.autocorrectionType = UITextAutocorrectionTypeNo;

我用过

myTextView.text = myTextView.text;

[myTextView insertText:@" "];
[myTextView deleteBackward];

[myTextView setNeedsDisplay];

这些都不起作用...

【问题讨论】:

  • 你能解释一下你说“它不起作用”是什么意思吗?它做了什么,你期望它做什么。
  • 当 UITextAutocorrectionTypeNo 文本停留在带有下划线的红点...我想删除它.​​. 我也在做这个 textContainerView.autocorrectionType=UITextAutocorrectionTypeNo; textContainerView.spellCheckingType=UITextSpellCheckingTypeNo;
  • 你写的第一段代码是正确的。这听起来更像是你把它放在哪里的问题。

标签: ios objective-c uitextview autocorrect


【解决方案1】:

当您更改此类属性(包括键盘类型)时,您通常必须“启动”该过程

// Original
myTextView.autocorrectionType = UITextAutocorrectionTypeYes;

... // 时间流逝

// Now want to change
myTextView.autocorrectionType = UITextAutocorrectionTypeNo;
BOOL bogusKeyboardMotion = YES; // ivar
[myTextView resignFirstResponder];
[myTextView becomeFirstResponder];
bogusKeyboardMotion= NO;

然后忽略委托方法中的任何委托消息。也许将委托设置为 nil 然后将其设置回来也可以。

【讨论】:

  • 当我改变这些属性时,键盘不是第一响应者,所以不是因为这个。这些选项在一个新的视图控制器中,所以键盘总是辞职......看我的回答..
【解决方案2】:

它只适用于这样的东西

NSString* textDirty=textContainerView.text;
    textContainerView.text=@"";
    textContainerView.text=textDirty;

但我想要一个更简洁的解决方案...另外,它仅将拼写检查应用于用户输入的新文本,而不是整个 uitextview 文本..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-08
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    相关资源
    最近更新 更多