I am trying to observe the int (totalSeconds) property in a class (StopWatch), where the total number of seconds increases by one each time the time is triggered (one interval) by my custom class (DynamicLabel), the UILabel subclass should receive an observValueForKeyPath message every time the totalSeconds changes but he is never called. Here is the relevant code:
and in the view controller:
- (void)viewDidLoad { [super viewDidLoad]; watch = [[StopWatch alloc] init]; [watch addObserver:dLabel1 forKeyPath:@"totalSeconds" options:NSKeyValueObservingOptionNew context:NULL]; }
where dLabel is an instance of DynamicLabel
Does anyone know why this is happening? This definitely has something to do with NSTimer because I tried the same when I change the value of totalSeconds manually to check if KVO is working and it works fine. However, when totalSeconds increases in the timer fire method, the watchValueForKeyPath method is never called. In addition, for those who are wondering why I use KVO for this, this is due to the fact that in a real application (this is just a test application) I need to display several running stopwatch (at different times) on the screen and record the last time. I would like to do this using one beat. I would really appreciate any help I can get.
Thanks,
source share