Objective c iPhone编程:在UITextView中禁用拼写检查

Objective c iPhone编程:在UITextView中禁用拼写检查,objective-c,uitextview,spell-checking,Objective C,Uitextview,Spell Checking,UITextAutocorrectionTypeNo对我不起作用 我正在为iPhone开发一个纵横字谜应用程序。 这些问题在UITextView中,我使用UITextFields作为每个字母的用户输入。 通过触摸问题(UITextView),第一个答案字符的文本字段将成为第一个响应者 虽然一切正常,但UITextView仍在检查拼写并标记问题中的错误单词, 即使我将它们设置为UITextAutocorrectionTypeNo //init of my Riddle-Class ... fo

UITextAutocorrectionTypeNo对我不起作用

我正在为iPhone开发一个纵横字谜应用程序。 这些问题在UITextView中,我使用UITextFields作为每个字母的用户输入。 通过触摸问题(UITextView),第一个答案字符的文本字段将成为第一个响应者

虽然一切正常,但UITextView仍在检查拼写并标记问题中的错误单词, 即使我将它们设置为UITextAutocorrectionTypeNo

//init of my Riddle-Class

...

for (int i = 0; i < theQuestionSet.questionCount; i++) {

    Question *myQuestion = [theQuestionSet.questionArray objectAtIndex:i];
    int fieldPosition = theQuestionSet.xSize * myQuestion.fragePos.y + myQuestion.fragePos.x;
 CrosswordTextField *myQuestionCell = [crosswordCells objectAtIndex:fieldPosition];
 questionFontSize = 6;
 CGRect textViewRect = myQuestionCell.frame;

 UITextView *newView = [[UITextView alloc] initWithFrame: textViewRect];
 newView.text = myQuestion.frageKurzerText;
 newView.backgroundColor = [UIColor colorWithRed: 0.5 green: 0.5 blue: 0.5 alpha: 0.0 ];
 newView.scrollEnabled = NO;
 newView.userInteractionEnabled = YES;
 [newView setDelegate:self];
 newView.textAlignment = UITextAlignmentLeft;
 newView.textColor = [UIColor whiteColor];
 newView.font = [UIFont systemFontOfSize:questionFontSize];
 newView.autocorrectionType = UITextAutocorrectionTypeNo;
 [textViews addObject:newView];
 [zoomView addSubview:newView];
 [newView release];
}

...

//UITextView delegate methode in my Riddle-Class

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView {

     textView.autocorrectionType = UITextAutocorrectionTypeNo;  

     for (int i = 0; i < [questionSet.questionArray count]; i++) {
      if ([[[questionSet.questionArray objectAtIndex:i] frageKurzerText] isEqualToString:textView.text]) {
        CrosswordTextField *tField = [self textfieldForPosition:
            [[questionSet.questionArray objectAtIndex:i] antwortPos]]; 
        markIsWagrecht = [[questionSet.questionArray objectAtIndex:i] wagrecht];
        if ([tField isFirstResponder]) [tField resignFirstResponder];
             [tField becomeFirstResponder];
        break;
      }
 }
 return NO;
}
//我的Riddle类的init
...
for(int i=0;i

我没有在任何其他地方调用UITextView。

找到了解决方案,但实际情况并非如此。 如果有人知道的更好,请告诉我

在第一次触摸后执行自动更正。 因此,我分配了一个新的UITextView,并将其设置为触摸文本视图。 然后我用新的textView替换触摸过的textView。 因此,每个UITextView实例只能触摸一次并消失。:)

//my Riddle类中的UITextView委托方法
-(BOOL)文本视图应开始编辑:(UITextView*)文本视图{
…这里第一篇文章的代码。。。
//新增代码:
对于(int i=0;i<[textViews计数];i++){
if(textView==[textViews objectAtIndex:i]){
UITextView*trickyTextView=[[UITextView alloc]initWithFrame:textView.frame];
trickyTextView.text=textView.text;
trickyTextView.font=textView.font;
trickyTextView.autocorrectionType=UITextAutocorrectionTypeNo;
trickyTextView.textColor=textView.textColor;
trickyTextView.backgroundColor=textView.backgroundColor;
trickyTextView.delegate=self;
trickyTextView.scrollEnabled=否;
[textViews replaceObjectAtIndex:i with Object:trickyTextView];
[textView从SuperView移除];
[zoomView添加子视图:trickyTextView];
[trickyTextView发布];
打破
}
}
返回否;
}

我也有同样的问题。解决方案非常简单,但没有文档记录:您只能更改
uitextraits
协议中定义的属性,而所讨论的
UITextView
不是第一响应者。以下几行为我修复了它:

[self.textView resignFirstResponder];
self.textView.autocorrectionType = UITextAutocorrectionTypeNo;
[self.textView becomeFirstResponder];

希望这对某人有所帮助。

下面是一个可能有用的提示,来自的答案:

如果您有子类UITextView,则可以覆盖
becomeFirstResponder
的子类实现中的
uitextRaits
,如下所示:

-(BOOL)becomeFirstResponder {
    self.spellCheckingType = UITextSpellCheckingTypeNo;
    self.autocorrectionType = UITextAutocorrectionTypeNo;
    self.autocapitalizationType = UITextAutocapitalizationTypeNone;
    return [super becomeFirstResponder];
}
这样就没有必要明确地
辞职
/
成为特质变化的第一反应者。
重要 禁用拼写检查将不会更新红线的用户界面,直到文本本身也被更新。仅仅将拼写检查设置为NO是不够的

要强制进行UI更新,请将拼写检查属性设置为否,然后切换文本空白,然后返回,如下所示:

_textView.spellCheckingType = UITextSpellCheckingTypeNo;

NSString *currentText = _textView.text;
NSAttributedString *currentAttributedText = _textView.attributedText;
_textView.text = @"";
_textView.attributedText = [NSAttributedString new];
_textView.text = currentText;
if (currentAttributedText.length > 0) {
    _textView.attributedText = currentAttributedText;
}

注意,如果也禁用拼写检查(红色下划线),则需要强制进行UI更新以消除红色的扭曲线。请看这里:
_textView.spellCheckingType = UITextSpellCheckingTypeNo;

NSString *currentText = _textView.text;
NSAttributedString *currentAttributedText = _textView.attributedText;
_textView.text = @"";
_textView.attributedText = [NSAttributedString new];
_textView.text = currentText;
if (currentAttributedText.length > 0) {
    _textView.attributedText = currentAttributedText;
}