0

I have an NSPopUpButton and even a simple subclass of NSPopUpButton. In the subclass I have:

- (BOOL)acceptsFirstResponder { return YES; }

- (BOOL)refusesFirstResponder { return NO; }

Now it's easy enough to tell the window to make the button first responder, and that works on launch, but I need this to also occur as nextResponder from tabbing out of an NSTextField. Once focus is on any NSTextField, it never seems to be able to move back to the popupbutton.

What am I missing here? It seems like it should be really simple.

ANSWER: firstResponder is not the thing to use here. A subclass is needed (as I suspected) and simply needs to override the following to return YES: - (BOOL)canBecomeKeyView { return YES; } (thanks Peter Hosey)

Monolo
  • 18,205
  • 17
  • 69
  • 103
uchuugaka
  • 12,679
  • 6
  • 37
  • 55
  • Can you give us a list of controls in the window and what is set for nextResponder on each of them? – Aaron Golden Mar 21 '13 at 17:39
  • Have you tried setting the previous view's `nextKeyView`? – Peter Hosey Mar 21 '13 at 23:09
  • Contains only an NSPopUpButton and an NSTextField. Tried setting nextKeyView both in code and in IB from one to the other, no effect. Seems like only the containing window is able to set the NSPopUpButton as firstResponder. Weird. – uchuugaka Mar 21 '13 at 23:15
  • @uchuugaka: Note that there is a distinction between the first responder and the key view. There is a separate `canBecomeKeyView` method. – Peter Hosey Mar 21 '13 at 23:18
  • aha!! `canBecomeKeyView {return YES;}` in my subclass did the trick. Please add as answer and I'll accept it! firstResponder was not the method I was looking for. – uchuugaka Mar 21 '13 at 23:22
  • What happens if you *don't* override that method, but you turn on full keyboard access in System Preferences? – Peter Hosey Mar 22 '13 at 06:11
  • Then every imaginable thing in the OS is accessible by keyboard. Not what I'm after. This is for a form that will be very frequently used in workflow, but everything in the UI doesn't necessarily need full keyboard access by default. – uchuugaka Mar 22 '13 at 13:06
  • You still need to post the answer as an answer... ;) – uchuugaka Mar 22 '13 at 13:07
  • Well, he will if he reads the post. @PeterHosey please add your answer below as an Answer so I can properly accept it... – uchuugaka Mar 22 '13 at 15:45
  • @Monolo: I actually do get notified for the next comment after my own. Not sure if that only applies to the questioner's or anybody's. – Peter Hosey Mar 22 '13 at 21:06
  • I think it's everyone. – uchuugaka Mar 23 '13 at 02:28

1 Answers1

4

In your NSPopUpButton subclass, try overriding canBecomeKeyView instead.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370