Why can't I observe the editing
property of an instance of UITableViewController
?
I'm using the following code:
[self addObserver:self
forKeyPath:@"editing"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:NULL];
And have implemented the method:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
... but the observeValueForKeyPath
method is never called when this value changes.
According to Apple's Ensuring KVC Compliance section:
For properties that are an attribute or a to-one relationship, this requires that your class:
- Implement a method named
-<key>
,-is<Key>
, or have an instance variable<key>
or_<key>
.- If the property is mutable, then it should also implement
-set<Key>:
.- Your implementation of the
-set<Key>:
method should not perform validation.- Your class should implement
-validate<Key>:error:
if validation is appropriate for the key.
The documentation for the editing
property, states that it is defined as:
@property(nonatomic, getter=isEditing) BOOL editing
Since this property is not mutable, the only bullet point it must conform to is the first one (i.e. that there is an -is<Key>
method defined, for example). You can see that it does conform to this by looking at the declaration of the property, and noticing that there is an isEditing
method defined. Thus, it should be Key Value Observing compliant. How come it isn't working?
setEditing:animated:
? – Quag