I am tracking a progress with a UIProgressView
and I set an observer to the property I'm tracking.
I add the observer in the viewWillAppear
, like this:
-(void)viewWillAppear:(BOOL)animated
{
[self addObserver:self forKeyPath:@"progress" options:0 context:nil];
}
And when I remove the observer in the viewWillDisappear, like this:
-(void)viewWillDisappear:(BOOL)animated
{
[self removeObserver:self forKeyPath:@"progress"];
}
And in the observeValueForKeyPath method I updated the progress view:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
if([keyPath isEqualToString:@"progress"])
{
[self.progressView setProgress:self.progress animated:YES];
}
}
Now when I leave this viewController
and I return the observeValueForKeyPath
is not being called and I don't get the progressView
continuously updated.
The behavior of the progressView according to the code above is shown in this video: https://youtu.be/PVRT_Jjtdh4