0

I have an NSPopuButton, and the first time I open it, it's slow, because it draws a lot of things. The second time and each time after that, it's very fast.

What can I do so the menu is prerendered, so it opens fast even the first time?

So far, I've tried creating the menu in applicationWillLaunch, and after creating it, I call popupMenuPositioningItem:atLocation:inView:.

This works just fine, but the problem is that it displays the menu on the screen. I tried creating an offscreen window and view, and opening the menu there, but it always gets drawn inside the screen.

Is there a way to prerender the menu, or display it but force it offscreen?

thanks.

pvinis
  • 4,059
  • 5
  • 39
  • 59

2 Answers2

0

You should find out why it takes so long. Most likely it's some sort of file-activity (like loading images or data) or computation. I don't think it's the drawing itself (It would draw slowly each time).

Use "Time Profiler" or "File Activity" Instruments to find offending method calls. Then either optimize that code or call it beforehand.

pointum
  • 2,987
  • 24
  • 31
  • i am making a font selector, and each font is drawn in the font itself. so what takes so long, is loading each font when it draws the names. so what i need is a way for the menu to load each font before the first time someone clicks on it. – pvinis Apr 16 '14 at 08:10
0

Another idea then. I would ditch the popup button and use a regular button with drop down icon. Clicking it shows NSPopover with NSTableView that has the list of fonts. Unlike menus, tables are optimized for showing lots of data and lazy loading. Initially it would only load fonts for visible rows.

pointum
  • 2,987
  • 24
  • 31