2

I have a large list - over 200 items - managed by an NSPopUpButton. When clicked, the list extends all the way to the top or bottom of the screen and beyond.

How can I limit the open size, so that at most 20 or so items are shown at once?

Mira
  • 161
  • 7

2 Answers2

6

The solution I found was the following:

I subclassed NSPopUpButton, and in my subclass defined confinementRectForMenu:onScreen: (part of the NSMenuDelegate protocol). This limits the space that the list takes up. Unfortunately, you can't just specify a size but must do the work to determine the position. You can take [self frame] origin, use [[self superview] convertPointToBase:], nudge it over a bit and do whatever other calculations, then do a final conversion with [[self window] convertBaseToScreen:].

Mira
  • 161
  • 7
4

200 items is too many for a pop-up menu. The Mac Human Interface Guidelines recommend that a pop-up menu should contain a maximum of 12 items.

You need to rethink your design. I suggest that instead of the pop-up menu, you create a single-column NSTableView with no header and let your users select an item from a scrollable list of options.

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • 3
    A typical StackOverflow answer: "You're doing it wrong!" :-) The trouble is I want this control to only take up one line - if I can get the NSTableView to "pop up" that would be lovely. – Mira Jul 28 '11 at 18:40
  • 2
    If you can target Lion then you could use a popover I suppose. However, my point is that you *are* doing it wrong and you should think of another way :-) – Rob Keniger Aug 01 '11 at 11:01