Re: NSPopUpButton addItemsWithTitles is way slow
Re: NSPopUpButton addItemsWithTitles is way slow
- Subject: Re: NSPopUpButton addItemsWithTitles is way slow
- From: Dave Camp <email@hidden>
- Date: Fri, 16 Aug 2002 09:27:06 -0700
On Friday, August 16, 2002, at 05:37 AM, Jeremy Dronfield wrote:
The main thing you're doing "wrong" is going against Apple's interface
guidelines, which recommend NSPopUpButtons for lists with 5-12 items.
20-50 items is pushing it, whereas 200 items...? For big collections,
they suggest using a scrollable list, unless window space is a serious
problem.
Space is a problem, and it's what the client wants... but I might
revisit this again.
All NSPopUpButton methods for adding/removing items call
-synchronizeTitleAndSelectedItem, which logically has to search for
and remove any duplicates. With 200 items there's inevitably going to
be a time penalty. You could try calling the equivalent -add methods
for NSPopUpButtonCell (which - I think - don't sychronize), but I'm
not sure how you'd go about it, and Apple recommends against doing it.
BTW, I posted the code you adapted. It's intended for an NSMenu, where
there's no synchronization issue. I adapted it from the MenuMadness
example project. If performance is a big issue, and you don't have
space for a scrollable list, I'd suggest putting your countries list
in an NSMenu.
Yes, I grabbed that code from your last post. Prior to that, my code
(which was equally fast) looked like:
int index;
int count = [items count];
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
for (index = 0; index < count; index++)
[menu addItemWithTitle:[items objectAtIndex:index] action:nil
keyEquivalent:@""];
[menu autorelease];
[popup setMenu:menu];
[popup synchronizeTitleAndSelectedItem];
That code was as fast as yours, but also the suffered the same problem
for the first Command key combination pressed.
If this is just the way Cocoa menus work, I guess I'll have to look at
re-designing some UI...
Dave
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.