I have two NSTextFields: textFieldUserIDand textFieldPassword.
For textFieldPasswordI have a delegate as follows:
- (void)controlTextDidEndEditing:(NSNotification *)aNotification
This delegate is called when it textFieldPasswordhas focus, and I press the enter key. This is exactly what I want.
My problem is that it is controlTextDidEndEditingalso called when it textFieldPasswordhas focus, and I move the focus to textFieldUserID(using the mouse or the tab key). This is NOT what I want.
I tried to use a notification controlTextDidChange(which is called once to press a key), but I was not able to figure out how to detect the input key ( [textFieldPassword stringValue]does not include the input key). Can someone please help me figure this out?
I also tried to find out what I textFieldUserIDwas firstResponder, but that didn't work for me. Here is the code I tried:
if ( [[[self window] firstResponder] isKindOfClass:[NSTextView class]] &&
[[self window] fieldEditor:NO forObject:nil] != nil ) {
NSTextField *field = [[[self window] firstResponder] delegate];
if (field == textFieldUserID) {
NSLog(@"is true");
}
}
Of course I could help here!
source
share