In my OS X App, how can I change the NSTextField
focus by pressing the Enter key instead of pressing the Tab key?
Asked
Active
Viewed 298 times
0
-
1What u want to do? Tab key switch focus to the next control by default in OS X and Enter - end editing. – Nikolai Nagornyi Feb 15 '14 at 14:17
-
I want press ENTER key to end editing and switch focus to the next control simultaneously. Is it Possible? – Max Colla Feb 15 '14 at 14:45
1 Answers
1
You may use NSText
- (void)textDidEndEditing:(NSNotification *)aNotification
delegate method, where you should use NSWindow
’s makeFirstResponder
: to change the current first responder. See the NSResponder class reference for details on this.
First set delegate
of your firs textField to self
. Then in same class:
- (void)textDidEndEditing:(NSNotification *)aNotification {
NSLog(@"delegate method");
[self.window makeFirstResponder:[[[aNotification object]window]nextResponder]];
}
I assume that you do this in AppDelegate class.

Nikolai Nagornyi
- 1,312
- 2
- 11
- 26
-
I tried to use this method: - (IBAction)changeFocus:(id)sender { NSResponder*resp=[sender nextResponder]; [myWindow makeFirstResponder:resp]; } and link this action to my Textfield press ENTER key, but it doesn't work - ?? – Max Colla Feb 15 '14 at 15:36
-
-
yes I'm sure, it seems that the [sender nextResponder] does not work – Max Colla Feb 15 '14 at 16:11
-
-
-
-
I realized that when invoke [sender nextResponder] -(sender is my NSTextfield)- the nextResponder is the NSView that contain all my textfield. At runtime instead when I press TAB key the focus change from one Textfield to another- suggestions? thx – Max Colla Feb 15 '14 at 17:51