Re: NSTextField binding problem [SOLVED]
Re: NSTextField binding problem [SOLVED]
- Subject: Re: NSTextField binding problem [SOLVED]
- From: Sean Todd <email@hidden>
- Date: Tue, 23 Nov 2004 17:09:25 -0600
Answering my own post (oops):
The cause of the strange behavior is due to the -willChangeValueForKey: and -didChangeValueForKey: calls in the following code:
-(void)observeValueForKeyPath:(NSString*)aKeyPath
ofObject:(id)anObject
change:(NSDictionary*)theChange
context:(void*)theContext
{
id oldValue = [theChange objectForKey:NSKeyValueChangeOldKey];
NSUndoManager* um = [document undoManager];
[[um prepareWithInvocationTarget:self] changeKeyPath:aKeyPath
ofObject:anObject
toValue:oldValue];
if ([aKeyPath isEqualToString:@"name"])
[um setActionName:NSLocalizedString(@"Set Name", nil)];
if ([aKeyPath isEqualToString:@"grade"])
[um setActionName:NSLocalizedString(@"Set Grade", nil)];
if ([aKeyPath isEqual:@"grade"])
{
[self willChangeValueForKey:@"assignments"];
[self didChangeValueForKey:@"assignments"];
}
}
Besides handling undos, I use this code for forcing an update of the re-calculated final grade in the tableview in the main window when an assignment grade is changed in the inspector window. Unfortunantly, bindings can't handle this automatically. If I remove the KVO willChange and didChange calls, the text field responds normally but the tableview in the main window doesn't update without manually selecting another student from the table in the main window and then re-selecting the original student. Interestingly, setting up a hack to do this switching programatically results in the same text field behavior as using the KVO willChange and didChange methods. It seems that I can have one or the other but not both.
Sean
Date: Mon, 22 Nov 2004 12:54:44 -0600
From: Sean Todd <email@hidden>
Subject: NSTextField binding problem
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes;
format=flowed
I have run across a problem where a particular text field (with number
formatter) 'looses' any change at the end of editing (cursor moved to
another field). Any ideas on what might be wrong or what to try next
would be appreciated.
Details:
I have an inspector window containing a table view with 2
columns—'assignment' and 'grade' (master view) and 2 text fields
(detail view) that show the data of the item selected in the table.
These are bound to an NSArrayController. The contentArray of the
controller is bound to 'Shared Application' via the path:
mainWindow.windowController.document.studentController.selection.assignm
ents. The problem is that when the grade is changed in the text field,
the grade displayed in the field reverts to the old entry even though
the new grade shows up in the table view. This is a one-way problem.
Any grade change in the table view shows up correctly in the text field
as do any changes made via undos. Moreover, no other text fields,
including the 'assignment' text field, show this behavior. The bindings
of both fields are setup the same way.
One other bit of wierdness, the method -controlTextDidEndEditing: does
not get called in the delegate when this happens.
Using Xcode 1.5.
What I've tried:
nibtool didn't show any problems
I went so far as to create a new inspector nib but the problem remained
I tried reproducing the problem in a simplified project but could not.
Thanks,
Sean
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden