model updates via binding thourh mpviewcontroller now get registered

This commit is contained in:
michael starke
2016-08-24 16:25:06 +02:00
parent 55ab84b6bd
commit f01480c2bd
2 changed files with 40 additions and 1 deletions

View File

@@ -14,7 +14,26 @@
- (void)didLoadView; - (void)didLoadView;
- (NSResponder *)reconmendedFirstResponder; - (NSResponder *)reconmendedFirstResponder;
/* Returns the associated window controller */
- (void)updateResponderChain; - (void)updateResponderChain;
#pragma mark Binding Observation
/**
* Override this to get notificied when setValue:forKeyPath will be called with a keypath starting with representedObject.
* This is always called via the binding system, hence it's usefull to anticipate model changes via the ui
*
* The default implementation calls this just befor setValue:forKeyPath:
*
* @param keyPath the full key path about to be affected
*/
- (void)willChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath;
/**
* Override this to get notified when setValue:forKeyPath was called with a keypath starting with representedObject.
* The default implementation calls this right after setValue:forKeyPath:
*
* @param keyPath the full key path affected
*/
- (void)didChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath;
@end @end

View File

@@ -38,4 +38,24 @@
} }
} }
#pragma mark Binding observation
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
if([keyPath hasPrefix:@"representedObject."]) {
[self didChangeValueForRepresentedObjectKeyPath:keyPath];
[super setValue:value forKeyPath:keyPath];
[self didChangeValueForRepresentedObjectKeyPath:keyPath];
}
else {
[super setValue:value forKeyPath:keyPath];
}
}
- (void)willChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath {
NSLog(@"[%@ willChangeValueForRepresentedObjectKeyPath:%@]", NSStringFromClass([self class]), keyPath);
}
- (void)didChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath {
NSLog(@"[%@ didChangeValueForRepresentedObjectKeyPath:%@]", NSStringFromClass([self class]), keyPath);
}
@end @end