1

How can I update my statusItem Title? At the moment I do it with a timer

[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myVoid) userInfo:nil repeats:YES];

and the void is:

-(void)myVoid {

statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setTitle:myString];

}

The content of myString changes. How can I update the Title? At the moment, when I update it there comes another statusItem and another and another...

Viper OS X
  • 291
  • 1
  • 5
  • 14

1 Answers1

3

Create the statusItem once and keep a reference to it in an ivar, then setTitle on that rather than creating a new statusItem each time (statusItemWithLength: creates a new item).

MattR
  • 6,908
  • 2
  • 21
  • 30
  • Thanks. You solved my problem. But can you say me, how can I make, that I can click on it? – Viper OS X Oct 06 '12 at 14:50
  • It depends what you want your statusItem to do... If you want a menu to appear then crate that menu in a NIB and set it on your statusItem using `setMenu:`, for a custom view, use `setView:` – MattR Oct 06 '12 at 14:53
  • I wrote an App that shows the temperature in the menu bar, but I must give it a quit button and for that I need a menu – Viper OS X Oct 06 '12 at 17:33