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/