limiting textField characters and tabbing to next field

Hi all, I'm using a few textFields for data entry in a MacOS app (and Objective-C). These entries will only be two characters in length (timecode), so when a user is done entering the first two digits, I want the cursor to tab over to the next textField.


I am using the <NSTextFieldDelegate> protocol and I have set the delegates using [self.hourTextField setDelegate:self]; (and for the other textFields as well in my ViewController.


I am also already using two delegate methods for other purposes...


- (void)controlTextDidChange:(NSNotification *)notification and

- (void)controlTextDidEndEditing:(NSNotification *)notification


Is there a delegate method that will tab to the next field when the two characters are entered? or a method I could use in one of these delegate methods? I've seen a few entries on this, but they are either for UITextField which looks like it behaves differently than in MacOS. I've also seen some posts but they have been in Swift and I haven't learned that yet.


Also, I tried using a number formater called Disc Recording MSF Formatter, but it crashes my app because I don't have a library, or something?


Thanks as always,

Accepted Reply

There's nothing that will do this automatically. In the delegate method, you would need to manally invoke "makeFirstResponder" on the window, passing the desired new text field as the parameter.


Note that if you have set up your key view loop suitably, you can invoke "selectNextKeyView(_:)" instead, which avoids the need to have an explicit reference to the next field, but it can be annoying to get the loop set up reliably, so it may not be worth the trouble.

Replies

There's nothing that will do this automatically. In the delegate method, you would need to manally invoke "makeFirstResponder" on the window, passing the desired new text field as the parameter.


Note that if you have set up your key view loop suitably, you can invoke "selectNextKeyView(_:)" instead, which avoids the need to have an explicit reference to the next field, but it can be annoying to get the loop set up reliably, so it may not be worth the trouble.

You should do it in - (void)controlTextDidChange:(NSNotification *)notification


testing if you have 2 characters that form a correct timeCode, then proceeding as Quincey described.

Okay, thanks Quincy and Claude, I will investigate. I don't know anything about "first responder," I've seen it and have wondered what it was, I guess it's time to go find out. Thanks...