2013-09-04 14 views
5

Sono nuovo allo sviluppo iOS.textViewDidEndEditing non è chiamato

ho scritto file di intestazione seguente come questo

@interface TextView : UITextView <UITextViewDelegate, UIPopoverControllerDelegate> 

in TextView.h.

Il codice file di implementazione è la seguente:

- (BOOL)textViewShouldBeginEditing:(TextView *)textView 
{ 
    ZWLog(@"called should begin edit"); 
    return YES; 
} 

- (void)textViewDidBeginEditing:(TextView *)textView 
{ 
    ZWLog(@"called did begin edit"); 
} 

- (BOOL)textViewShouldEndEditing:(TextView *)textView 
{ 
    ZWLog(@"called should end editing"); 
    return YES; 
} 

- (void)textViewDidEndEditing:(TextView *)textView 
{ 
    ZWLog(@"view did end edit"); 
    return YES; 
} 

- (BOOL)textView:(TextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 
{ 
    //my own code 
    return YES; 
} 

- (void)textViewDidChange:(TextView *)textView 
{ 
    //my own code 
} 

quando si digita un carattere in UITextView, ho ricevuto risposta da

  • textViewShouldBeginEditing.
  • textViewDidBeginEditing.
  • shouldChangeTextInRange.
  • textViewDidChange.

Ma non ho ricevuto risposta da textViewDidEndEditing o textViewShouldEndEditing. Hai idea del motivo per cui non vengono chiamati?

Grazie per le vostre risposte.

+0

Il metodo textViewDidEndEditing viene richiamato quando KeyBoard scompare in altre parole quando l'utente interrompe la digitazione nella vista testo e viene richiamato resignfirstresponder. –

+0

@GyanendraSingh: Grazie per il tuo commento. – Kirubachari

risposta

8

textViewDidEndEditing viene chiamato quando textfield si dimette il suo primo risponditore, quando la tastiera scompare.

2

assicurati di aver collegato il tuo delegato correttamente da .xib

e utilizzare i metodi indicati come è, e uno sguardo che verrà chiamato

-(BOOL)textViewShouldEndEditing:(UITextView *)textView 
{ 
    ZWLog(@"textViewShouldEndEditing"); 
    return TRUE; 
} 

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 
{ 
    ZWLog(@"shouldChangeTextInRange"); 
    // Any new character added is passed in as the "text" parameter 
    if ([text isEqualToString:@"\n"]) 
    { 
     [textView resignFirstResponder]; 
     return FALSE; 
    } 

    // For any other character return TRUE so that the text gets added to the view 
    return TRUE; 
} 
0

fare in modo che il delegato è inserito nel tuo file XIB con il tuo TextView se è nel file XIB.

Problemi correlati