angry_kiwi angry_kiwi - 4 months ago 16
Objective-C Question

status bar icon showed for one second then disappear

I'm trying some stuff, to test the status bar icon feature.

I think I got the all the functions right. However when run. The icon displayed for about 1 mili second then disappeared.

Below is the screenshot of my code:

the code

source code: https://www.dropbox.com/sh/drdxi2zgumc4c3l/s-4J1S418s

Demo video: https://dl.dropbox.com/u/8032222/the%20app%20run%20weird.mov

Answer

Retain statusItem object.

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

From Documentation of statusItemWithLength:.

The receiver does not retain a reference to the status item, so you need to retain it. Otherwise, the object is removed from the status bar when it is deallocated.