Bindings Update with Drag-and-Drop [solved]
Bindings Update with Drag-and-Drop [solved]
- Subject: Bindings Update with Drag-and-Drop [solved]
- From: K.Darcy Otto <email@hidden>
- Date: Sat, 18 Apr 2009 07:56:18 -0700
I've managed to solve this problem. For those who might be looking at
this problem sometime in the future, note that in the code below,
there would be no need for -willChangeValueForKey: and -
didChangeValueForKey: in any case, since -setValue:forKey: does that
work anyway – -willChangeValueForKey: and -didChangeValueForKey: are
only needed if @"stringValue" is not being set by referencing the key
(i.e., [self setStringValue:draggedFormulaString]).
Here is the code that got it working for me:
// Get information about the object and path to which @"value" is
bound
NSDictionary *bindings = [self infoForBinding:@"value"];
id boundObject = [bindings valueForKey:NSObservedObjectKey];
id keyPath = [bindings valueForKey:NSObservedKeyPathKey];
// Set the keyPath of boundObject to draggedFormulaString
[boundObject setValue:draggedFormulaString forKeyPath:keyPath];
On 17-Apr-09, at 7:50 PM, K. Darcy Otto wrote:
I have a number of NSTextFields that are happily bound to NSString
objects in the controller, and they work very well: if the textfield
is updated, the corresponding NSString object is updated, as vice-
versa. Now, in order to implement drag-and-drop, I have had to
subclass NSTextField and set my textfields to that subclass.
Everything works fine (including typing, paste, and the like) in
terms of updating bindings, with the exception of drag-and-drop.
The problem is that when I drag-and-drop, the corresponding NSString
object is not updated. The textfield display is updated. Here is
the code I'm using in the textfield subclass:
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
...
[self willChangeValueForKey:@"stringValue"];
[self setValue:draggedFormulaString forKey:@"stringValue"];
[self didChangeValueForKey:@"stringValue"];
return YES;
}
Since I do not know the NSString object to which the textfield is
bound at design time, I can't simply go in and set the value of the
NSString and (hopefully) trigger a binding update. Is there any way
to find out which NSString the textfield is bound to? Is there some
other solution? Thanks.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden