objective-c - iPhone编程: Deactivate spell check in UITextView

标签 objective-c uitextview spell-checking

UITextAutocorrectionTypeNo 对我不起作用。

我正在为 iPhone 开发一个填字游戏应用程序。 问题在 UITextViews 中,我使用 UITextFields 作为每个字母的用户输入。 通过触摸一个问题 (UITextView),第一个答案字符的 TextField 变为 FirstResponder。

一切正常,但 UITextViews 仍在进行拼写检查并标记问题中的错误单词, 即使我设置了它们 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。

最佳答案

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

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

希望这对某人有帮助。

关于objective-c - iPhone编程: Deactivate spell check in UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3318827/

相关文章:

ios - 如何将UITextView的光标移动到TOUCHED LOCATION?

vim - Vim 中光标下的拼写检查单词

ios - 为什么我的节点没有出现在 SpriteKit 模板中?

ios - UIPageViewController 向前转动时加载缓慢,但不会向后转动

ios - UITextView:如何真正禁用编辑?

notepad - 为记事本配备拼写检查(键入时)功能 - 可用的最佳选择?

来自mysql的php名称拼写更正

objective-c - 如何在 XCode 4.2 中更改模型中不同 Controller 的数据

iphone - iOS 中从左向右滚动时如何获取 Web View 中的滚动方向?

ios - 设置委托(delegate)时无法单击 textView