I need to update the value of a NSProgressIndicator through a class different from the one where the outlet was defined.
Es:
Istead if i call the same method within class A it works fine.
What am I missing ?
//REQUESTED CODE:
//Class A (AppDelegate)
A.m
//Other stuff
-(void)update_indicator:(double)value {
//Method that updates the value of the indicator
[progress_indicator setDoubleValue:(double)value];
[progress_indicator setNeedsDisplay:YES];
}
//Class B (Drawing class - subclass of NSView)
B.m
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
//Create istance;
A *istance = [[A alloc] init]; //Alloc class A and init it
[A update_indicator:50.0];
//Other code..
}
The strange thing is that if I call -(void)update_indicator:(double)value
within class A, where the outlet is defined, it works fine, if I call it from B it is being called but the progress bar is not showing.
If A is the delegate class of the application you can get the good instance using this [[NSApplication sharedApplication]delegate]
, instead of creating a new instance.
Otherwise, you should make class A a singleton.
Take a lock at this example http://www.galloway.me.uk/tutorials/singleton-classes/