iPhone编程:停用UITextView中的拼写检查 [英] iPhone Programming: Deactivate spell check in UITextView

查看:104
本文介绍了iPhone编程:停用UITextView中的拼写检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UITextAutocorrectionTypeNo对我不起作用.

UITextAutocorrectionTypeNo didn't work for me.

我正在为iPhone使用填字游戏. 问题在UITextViews中,我使用UITextFields作为每个字母的用户输入. 通过触摸一个问题(UITextView),第一个答案char的TextField成为FirstResponder.

I'm working on a crossword app for the iPhone. The questions are in UITextViews and I use UITextFields for the User-Input of each letter. By touching a question(UITextView), the TextField for the first answer char becomesFirstResponder.

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

It all works fine but the UITextViews are still spell checking and mark the wrong words in the question, even if I set them 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;
}

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

I don't call UITextView on any other place.

推荐答案

我遇到了同样的问题.该解决方案非常简单,但没有记录在案:只有当所讨论的UITextView不是第一响应者时,您才能更改UITextInputTraits协议中定义的属性.以下几行为我修复了该问题:

I had the same problem. The solution is very simple but not documented: You can only change the properties defined in the UITextInputTraits protocol while the UITextView in question is NOT the first responder. The following lines fixed it for me:

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

希望这对某人有帮助.

这篇关于iPhone编程:停用UITextView中的拼写检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆