I’ve set up KVO notification to watch some properties of a UIWebView like so
[webView addObserver:self
forKeyPath:@"canGoBack"
options:NSKeyValueObservingOptionNew
context:NULL];
and have
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
but it never gets called. Am I missing something or is UIWebView just not observable?
canGoBackis areadonlyproperty: in order for it to be KVO compliant it would have to redeclare that property asreadwritein its implementation and then set the property via a synthesised setter. I suspect that insteadcanGoBackis just set via its ivar, which would not send a notification via the KVO system:This related question discusses the issue in detail: Is it possible to observe a readonly property of an object in Cocoa Touch?
As a workaround, you could set a
UIWebViewDelegateand check the value of[UIWebView canGoBack]in[UIWebViewDelegate webViewDidFinishLoad:].