tags:

views:

47

answers:

1

I've got an application with an NSLevelIndicator Object on it that's refusing to update.

I have a timer that's shoved off during init and updates the value of the NSLevelIndicator using its setIntValue method. Whilst the code executes without any exceptions, the NSLevelIndicator never visually updates. I have some other labels on the window that are updating through this timer, so I know that it is executing.

I've tried using all of the setTypeValue methods (String, straight value and double with appropriate variables being assigned in each). I even tried linking the "setStringValue" action through interface builder from the NSLevelIndicator to a label representation on the window to no avail. It still sits at its initial value (0).

I noticed that setIntValue (and all the other setTypeValue methods) are undocumented in Apple's documentation for NSLevelIndicator - so I'm wondering if I'm approaching this wrong.

Does anyone have any clue what the proper way to set an NSLevelIndicator's value from code is?

+1  A: 

setIntValue should work, so it sounds like your IBOutlet for the NSLevelIndicator isn't set properly - most likely its value is nil.

This is probably due to your outlet not being connected in IB, as Johan Kool suggested.

One thing worth mentioning, however, is that IBOutlets don't yet have a valid value at the time your initializer is called - they're hooked up after the initializer returns and shouldn't be referenced until your instance receives the awakeFromNib message.

You mentioned your timer is set up from your initializer - if you happen to be passing your instance's NSLevelIndicator pointer to the timer as its userInfo parameter, the userInfo will have the wrong value (nil) since it isn't yet initialized when the timer is created.

Regardless of whether you use userInfo this way, anything that depends on IBOutlet values should be set up from within awakeFromNib rather than init.

tedge
It was indeed the outlet not being connected (as Johan pointed out). Thank you for pointing that out as a suggestion. I'm just beginning OSX development, so I'm still not quite used to the dragging of outlets.Thank you, also, for the elaborated answer including the initialization order of the outlets. I will keep that in mind for the future.
phantomdata