• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSStatusItem:setImage - Icon not displaying
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSStatusItem:setImage - Icon not displaying


  • Subject: Re: NSStatusItem:setImage - Icon not displaying
  • From: John Stiles <email@hidden>
  • Date: Tue, 2 Aug 2005 22:41:56 -0700


On Aug 2, 2005, at 9:52 PM, James Bush wrote:

My application puts a menu (NSMenu) in the system status bar (NSStatusBar). I can set the title of the menu to any string value (NSStatusItem:setTitle), but cannot set the title to an image (NSStatusItem:setImage). Here's the code:

- (void)awakeFromNib
{
NSImage *menuImage = [[NSImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"image.png" ofType:@"png"]];
NSStatusBar *bar = [NSStatusBar systemStatusBar];
theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];
[theItem setImage:menuImage];
[theItem setHighlightMode:YES];
[theItem setMenu:theMenu];
}


This code compiles without error or warning. When the build is run, the menu can be displayed by clicking the location where the image file should be.

The problem could be unrelated to the code, as well. For example:
1. Perhaps I've imported the image file into the project incorrectly. Maybe it's not in the right location inside the project folder or is in the wrong group. I cannot find decent documentation on how to import images for use within your application.
2. Perhaps the image file is in the correct location in the project folder (and in the right group), but the URL is not correctly specified.


I'm tapped out on this one. None of the books I've bought, Apple's documentation, Google and about 5 Cocoa Dev web sites have an answer that works.

Your theories are easy to test... how about: assert( menuImage != nil );

Or just step through it in the debugger and see what values come out.
I have no experience with status items but it seems like you should be able to make a pretty accurate diagnosis with the tools you already have.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >NSStatusItem:setImage - Icon not displaying (From: James Bush <email@hidden>)

  • Prev by Date: Re: NSOutlineView and the trash can, take 2
  • Next by Date: RE: NSOutlineView and the trash can, take 2
  • Previous by thread: NSStatusItem:setImage - Icon not displaying
  • Next by thread: Mixing C++ with Objective C
  • Index(es):
    • Date
    • Thread