In a document-based project I am trying to create a status menu. I have a singleton class that builds the status bar, and I am initiating it from an application delegate, as you
You declared myStatusMenu
as an outlet, but never loaded a nib (or assigned anything to it yourself). An outlet cannot get objects out of nowhere; the outlet is set only when you load a nib that has the outlet connected to something (or assign something to the variable yourself, as if it weren't an outlet).
You can prove this by adding a line to buildStatusItem
that logs the value of the myStatusMenu
instance variable. I expect that it will be nil
.
What you need to do is:
KBStatusMenu
.init
to load the nib you just created.Then, by the time you reach buildStatusItem
, loading the nib will have set the outlet, and you will have a menu to give to your status item.
I would recommend only creating one KBStatusMenu
instance. In this case, I recommend enforcing the singleton: init
should test whether gInstance
has already been set and, if so, return that; only if it hasn't should it initialize and return self
.