key-value-observing

Cocoa Bindings for hierarchical model

一世执手 提交于 2019-12-01 09:13:50
问题 I have a NSCollectionView based master-detail interface, where I want to display Boards in the master and Lists+Cards in the detail view. Board , holds a NSMutableArray property lists of type List List , holds a NSArray property cards of type Card Card , has a NSString property name The relationship is thus Board --> to-many List --> to-many Card The master interface is fine. The detail interface gets populated with corresponding Lists' titles for a Board. Within the detail interface I also

How to observe NSScroller changes?

只谈情不闲聊 提交于 2019-12-01 06:22:32
I have an NSScrollView subclass and I would like to update another NSView based on the current scroll position. I tried KVC-observing the value of [self horizontalScroller] but that never gets called. // In awakeFromNib [[self horizontalScroller] addObserver:self forKeyPath:@"value" options:NSKeyValueObservingOptionNew context:NULL]; // Later in the file - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (object == [self horizontalScroller] && [keyPath isEqualToString:@"value"]) { // This never gets called } } Do

How to observe NSScroller changes?

感情迁移 提交于 2019-12-01 04:16:45
问题 I have an NSScrollView subclass and I would like to update another NSView based on the current scroll position. I tried KVC-observing the value of [self horizontalScroller] but that never gets called. // In awakeFromNib [[self horizontalScroller] addObserver:self forKeyPath:@"value" options:NSKeyValueObservingOptionNew context:NULL]; // Later in the file - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (object ==

NSSortDescriptor on transient attribute for NSFetchedResultsController

强颜欢笑 提交于 2019-12-01 03:54:28
Ok, I initially wanted to make NSSortDescriptor of a request for NSFetchedResultsController to sort based on the property in my NSManagedObject subclass, but It obviously won't do it, because NSFetchedResultsController is limited to predicates and sort descriptors that work on the fetched entity and its relations, so I decided to create a transient attribute in my data model, synthesis the property for this attribute to ivar in my NSManagedObject subclass, and sort based on it. When running it, i got while executing fetch 'NSInvalidArgumentException', reason: 'keypath isActive not found in

KVO and NSMutableArray

[亡魂溺海] 提交于 2019-12-01 03:41:40
How can I set KVO (key-value-observing) with an NSMutableArray ? I want to be notified when a change appears in the array. I never used KVO before with a collection like an array. Joe Osborn I think you'll be interested in the answers to this question . The key is that you can't observe any properties on the array directly—the array is just storage—but you can observe the to-many relationship that's backed by that array (here I'm assuming your array is a property on an object somewhere). If you don't want to use those special accessors all over the place, your code that owns the array can call

Is it possible to observe a readonly property of an object in Cocoa Touch?

自古美人都是妖i 提交于 2019-12-01 02:52:10
I've attempted to observe the (readonly) visibileViewController property of a UINavigationController with no success. I was able to successfully observe a readwrite property I defined myself for testing purposes on another class. Is it possible to observer readonly attributes? Barry Wark Yes, it is possible to observe read-only properties. However, if the object that declares that property makes changes to the value of that property in a way that is not Key-Value Observing compliant (e.g. changes the value of the instance variable backing that property directly without seding

What does “Controller Key” mean in Interface Builder > Inspector > Bindings?

倖福魔咒の 提交于 2019-11-30 21:47:49
I can't find in the Docs where they explain all those fields and what they mean. Especially "Controller Key" is not clear to me. The Controller Key pop-up menu is a way to help you discover what keys the controller (typically a NSArrayController, NSObjectController or a NSTreeController) presents. The best example is the selection key of NSArrayControllers, which contains the set of selected objects. What is confusing is the NSObjectController presents a 'selection' key too, although the controller can control only a single object (therefore the selection = the object). I agree that it is not

In Cocoa KVO, why doesn't a change on a NSMutableArray proxy notify observers?

这一生的挚爱 提交于 2019-11-30 20:31:46
I'm implementing a DocumentsManager class in iOS, and I want to make a to-many property called documents to be KVO compliant. It seems to mostly work, and my KVO accessor and mutator methods are called. The thing that bothers me, however, is that any change made directly on the NSMutableArray proxy returned by calling mutableArrayValueForKey: on my instance doesn't notify observers. So, this code notifies me about the insertion of @"aaa" but not of @"bbb" , although they are both actually inserted in visible in docsProxy . Is that expected behavior? If so, what is the advantage of using the

Key-Value Observing an NSMutableSet

孤街浪徒 提交于 2019-11-30 19:46:53
In a plain class I have a NSMutableSet property. Whenever objects are added to or removed from the set, I want to perform some custom code. I know I could write a few addObjectToSet: -like methods to the class, but I was wondering if there's a more elegant solution with direct KVO on the set. As it turns out, NSSet will raise an exception when you try to add an observer to it. Not surprisingly, for there's probably no named keyPath to observe. The documentation is pretty clear about the exception, but I don't understand the suggested workaround: Instead of observing a set, observe the

An -observeValueForKeyPath:ofObject:change:context: message was received but not handled

怎甘沉沦 提交于 2019-11-30 14:31:04
问题 I am relatively new to KVO, so there is a good chance that I am violating some fundamental rule. I am using Core Data. My app crashes with the following message: And what I can't understand is why a CGImage is getting involved in observing a value that is set on a MeasurementPointer object. *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<CGImage 0x276fc0>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled. Key