views:

103

answers:

2

I have a NSStatusItem called statusItem created in my AppDelegate. I want to change the tooltip in the instance of NSStatusItem in a different object, but don't know how to do so since I'm still getting the hang of the Objective C language coming from Basic.

How should I implement this?

+1  A: 

First, add a method to the AppDelegate:

-(void)setStatusToolTip:(NSString*)toolTip
{
    [statusItem setToolTip:toolTip];
}

Now, in the other object from which you want to change the tooltip, do this:

AppDelegate* appDelegate=[NSApp delegate];
[appDelegate setStatusToolTip:@"new tool tip!"];
Yuji
That worked. Thanks. :)
chikorita157
A: 

You might also consider moving the status item creation and ownership from the app delegate to the object that needs to set its tooltip.

Peter Hosey
The problem with moving the StatusItem creation is that I would have to move everything else, which becomes a big mess. I want to keep the API interaction related functions separate from the graphical stuff (Window, Status Item, Preference Windows, etc).
chikorita157