iPhone Programming: Деактивируйтесь проверяют правописание в UITextView

UITextAutocorrectionTypeNo не работал на меня.

Я работаю над приложением кроссворда для iPhone. Вопросы находятся в UITextViews, и я использую UITextFields для Ввода данных пользователем каждой буквы. Путем касания вопроса (UITextView), TextField для первого символа ответа becomesFirstResponder.

Все это хорошо работает, но 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 ни на каком другом месте.

9
задан Thorsten 23 July 2010 в 14:21
поделиться

1 ответ

Есть решение, но оно не совсем то, каким должно быть. Если кто-то знает что-то лучше, пожалуйста, скажите мне.

Автокоррекция выполняется после первого касания. Поэтому я создаю новый 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;
}
0
ответ дан 4 December 2019 в 07:04
поделиться