Obtenga valor de NSTextField


Tengo un NSTextField y necesito obtener el valor del campo en una variable. ¿Cuál es el método apropiado?

Author: Josh Caswell, 2009-06-12

4 answers

Para un NSString usarías:

NSString *myString = [theTextField stringValue];

Para un int usarías:

int myInt = [theTextField intValue];

Hay muchos otros métodos para obtener el valor de un control. Echa un vistazo a la referencia NSControl para obtener más información, en la sección "Obtener y Establecer el valor del control" .

Aquí hay una lista:

  • doubleValue
  • floatValue
  • intValue
  • integerValue
  • objectValue
  • stringValue
  • attributedStringValue
 111
Author: toholio,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-02 06:08:50

[myField stringValue]

NSTextField hereda de NSControl, y NSControl define el stringValue/setStringvalue: métodos.

 3
Author: NilObject,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-02 06:07:03

Swift 3.versión x:

myField.stringValue
 2
Author: Stanley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-25 02:27:53

También:

Digamos que tienes un objeto (MyObject) que quiere ser notificado cuando alguien escribe en un NSTextField. En el .h archivo, MyObject debe declarar que se ajusta a NSTextFieldDelegate, como en...

@interface MyObject : NSObject <NSTextFieldDelegate>

A continuación, se establece myObject como el delegado de la NSTextField

[myTextField setDelegate:myObject]

Ahora, puede averiguar cuándo sucede algo en el campo de texto implementando métodos en myObject como:

-(void)controlTextDidEndEditing:(NSNotification *)aNotification;
-(void)controlTextDidChange:(NSNotification *)aNotification;
-(void)controlTextDidBeginEditing:(NSNotification *)aNotification;
 0
Author: The Cappy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-18 20:34:00