10

Tengo una UITextField con este NSNotification:texto de UITextFieldTextDidChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@"UITextFieldTextDidChangeNotification" object:_searchTextField]; 

- (void)textFieldDidChange :(NSNotification *)notif 
    { 
    // 
    } 

El NSLog es cuando escribo en r

NSConcreteNotification 0x193c20 {name = UITextFieldTextDidChangeNotification; object = <UITextField: 0x15a980; frame = (20 20; 280 31); text = 'r'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15aad0>>} 

¿Cómo consigo el texto r fuera del objeto entr?

+0

Se debe utilizar la UITextFieldTextDidChangeNotification constante (declarada en UITextField.h) en lugar de pasar su propio NSString como el argumento "nombre" –

Respuesta

16

La propiedad de notificación object almacena el campo de texto cuyo texto cambió, por lo que notif.object.text contendría el texto "r".

+0

Su dando un error - Propiedad 'texto' que no se encuentra en el objeto de tipo 'id' – daidai

+6

Do ' [(UITextField *) notif.object text] 'instead – yuji

+1

Ah sí, entonces tuve que: UITextField * txt = (UITextField *) notif.object; NSlog (@ "% @", txt.text); – daidai

Cuestiones relacionadas