Update statusItem Title
-
05-07-2021 - |
Domanda
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...
Soluzione
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).
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow