I have a simple Viewcontroller that meets the requirements of KVO and has the following in it:
- (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self addObserver:self forKeyPath:@"importStuff" options:0 context:NULL]; [self addObserver:self forKeyPath:@"importStuffFailed" options:0 context:NULL]; } - (void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self removeObserver:self forKeyPath:@"importStuff"]; [self removeObserver:self forKeyPath:@"importStuffFailed"]; }
The problem with im is that sometimes the user reports the following error:
Cannot remove an observer <MyViewController 0x145d0c8d0> for the key path "importStuff" from <MyViewController 0x1741b2280> because it is not registered as an observer.
the addObserver call is not called anywhere in the code. Is it something about the life cycles that they lack? is not viewDidAppear is guaranteed to be called once (so that it registers the keys correctly?)
source share