Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Turning NSMenuItem into separator



This is the approach I have ended up taking. However, I'm adding images to the menu that come from application icons. One of my application's icons are not loading on the first build. But if the menu ever needs to be re-built, the icon appears every time after.

for (i = 0;i < [cachedSuiteApplications count];i++) {
NSBundle *bundle = [NSBundle bundleWithIdentifier: [cachedSuiteApplications objectAtIndex:i]];
if (bundle != nil) {
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[bundle objectForInfoDictionaryKey:@"CFBundleName"] action:@selector(suiteMenuAction:) keyEquivalent:@""];
[item setTag:i];
[item setIndentationLevel:1];
path = [[bundle resourcePath] stringByAppendingString:@"/"];
path = [path stringByAppendingString:[bundle objectForInfoDictionaryKey:@"CFBundleIconFile"]];
img = [[NSImage alloc] initByReferencingFile:path];
[img setSize:NSMakeSize(16,16)];
[item setImage:img];
[item setTarget:self];
[suiteMenu addItem:item];
[item release];
}
}


What is it I'm doing wrong?


-- Thom McGrath Lead Programmer of The ZAZ Studios <http://www.thezaz.com>

On Sep 30, 2005, at 1:48 AM, Andy Lee wrote:

Alternatively, you could try organizing your app so that you construct the menu ahead of time, not by using these delegate methods, which don't get called until the menu is about to be displayed. This may not be practical for your particular application, but if you can do it this way, you'll know you're doing everything by the book.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Turning NSMenuItem into separator (From: Thom McGrath <email@hidden>)
 >Re: Turning NSMenuItem into separator (From: Andy Lee <email@hidden>)
 >Re: Turning NSMenuItem into separator (From: Andy Lee <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.