Look into KVO — Key-Value Observing — to trigger an action when a variable changes its value.
In your view controller's -viewWillAppear:
method, for example, add the observer:
[self addObserver:self forKeyPath:@"myBoolean" options:NSKeyValueObservingOptionNew context:nil];
In your -viewWillDisappear:
method, unregister the observer:
[self removeObserver:self forKeyPath:@"myBoolean"];
It's important to do this last step, so that the -dealloc
method doesn't throw an exception.
Finally, set up the observer method to do something when there is a change to myBoolean
:
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqual:@"myBoolean"]) {
// The BOOL value of myBoolean changed, so do something here, like check
// what the new BOOL value is, and then turn the indicator view on or off
}
}
The Key-Value Observing pattern is a good, general way to trigger something when an object's value changes somewhere. Apple has written a good "quick-start" document that introduces this topic.