iPhone编程:在UITextView中停用拼写检查

Tho*_*ten 9 spell-checking objective-c uitextview

UITextAutocorrectionTypeNo对我不起作用.

我正在研究iPhone的填字游戏应用程序.问题在UITextViews中,我使用UITextFields作为每个字母的User-Input.通过触摸问题(UITextView),第一个答案char的TextField成为FirstRirstResponder.

一切正常但是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;
}
Run Code Online (Sandbox Code Playgroud)

我不会在任何其他地方调用UITextView.

Eng*_*epe 22

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

[self.textView resignFirstResponder];
self.textView.autocorrectionType = UITextAutocorrectionTypeNo;
[self.textView becomeFirstResponder];
Run Code Online (Sandbox Code Playgroud)

希望这有助于某人.


jdc*_*jdc 8

Engin Kurutepe回答的一个可能有用的提示:

如果你有子类UITextView,你可以覆盖UITextInputTraits子类实现becomeFirstResponder,如下所示:

-(BOOL)becomeFirstResponder {
    self.spellCheckingType = UITextSpellCheckingTypeNo;
    self.autocorrectionType = UITextAutocorrectionTypeNo;
    self.autocapitalizationType = UITextAutocapitalizationTypeNone;
    return [super becomeFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)

因此,无需明确resign/ becomeFirstResponder围绕您的特征变化.


Tho*_*ten 0

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

在第一次触摸后执行自动更正。所以我分配一个新的 UITextView 并将他设置为触摸的 TextView。然后我用新的 TextView 替换触摸的 textView。因此每个 UITextView 实例只能被触摸一次并消失。:)

//UITextView delegate method in my Riddle-Class

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

    ...CODE FROM FIRST POST HERE...

    // ADDED CODE:
    for (int i = 0; i < [textViews count]; 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 = NO;
            [textViews replaceObjectAtIndex:i withObject:trickyTextView];
            [textView removeFromSuperview];
            [zoomView addSubview:trickyTextView];
            [trickyTextView release];
            break;
        }
    }
    return NO;
}
Run Code Online (Sandbox Code Playgroud)