Tengo dos NSTextField
s: y textFieldPassword
.NSTextField Enter key detection o firstResponder detection
Para textFieldPassword
, que tienen un delegado de la siguiente manera:
- (void)controlTextDidEndEditing:(NSNotification *)aNotification
Este delegado se llama cuando textFieldPassword
tiene el foco y me golpeó la tecla enter. Esto es exactamente lo que quiero.
Mi problema es que controlTextDidEndEditing
también se llama cuando textFieldPassword
tiene el foco y muevo el foco a textFieldUserID
(mediante el mouse o la tecla de tabulación). Esto no es lo que quiero.
Intenté usar la notificación controlTextDidChange
(que se llama una vez por pulsación de tecla) pero no pude averiguar cómo detectar la tecla Intro ([textFieldPassword stringValue]
no incluye la tecla Intro). ¿Puede alguien ayudarme a resolver esto?
También traté de detectar si textFieldUserID
era firstResponder
, pero no funcionó para mí. Este es el código que probé:
if ([[[self window] firstResponder] isKindOfClass:[NSTextView class]] &&
[[self window] fieldEditor:NO forObject:nil] != nil) {
NSTextField *field = [[[self window] firstResponder] delegate];
if (field == textFieldUserID) {
// do something based upon first-responder status
NSLog(@"is true");
}
}
¡De seguro podría necesitar ayuda aquí!
Sírvanse proporcionar detalles sobre cómo este código responde a la pregunta. – JAL