2010-07-23 14 views
8

UITextAutocorrectionTypeNo non ha funzionato per me.Programmazione iPhone: Disattiva controllo ortografico in UITextView

Sto lavorando a un'applicazione cruciverba per iPhone. Le domande sono in UITextViews e io uso UITextFields per l'input dell'utente di ogni lettera. Toccando una domanda (UITextView), il campo di testo per la prima risposta char diventa FirstResponder.

Funziona tutto bene ma le UITextViews sono ancora il controllo ortografico e segnano le parole sbagliate nella domanda, anche se li ho impostati 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; 
} 

Non chiamo UITextView in nessun altro posto.

risposta

0

Hai una soluzione ma non è proprio come dovrebbe essere. Se qualcuno sa qualcosa di meglio, per favore dimmelo.

La correzione automatica viene eseguita dopo il primo comando. Quindi assegno un nuovo UITextView e lo imposta come TextView toccato. Quindi sostituisco il textView toccato con il mio nuovo TextView. Quindi ogni istanza di UITextView può essere toccata solo una volta e scompare. :)

//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; 
} 
20

Ho avuto lo stesso problema. La soluzione è molto semplice ma non documentata: è possibile modificare solo le proprietà definite nel protocollo UITextInputTraits mentre il UITextView in questione NON è il primo risponditore. Le seguenti righe lo hanno risolto per me:

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

Spero che questo aiuti qualcuno.

8

One potenzialmente utili punta a seguito dalla risposta Engin Kurutepe s':

Se avete sottoclasse UITextView, è possibile ignorare la UITextInputTraits nell'attuazione sottoclasse di becomeFirstResponder, qualcosa di simile:

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

Ci non è quindi necessario esplicitamente resign/becomeFirstResponder attorno alle modifiche del tratto.

Problemi correlati