Created
June 23, 2009 14:38
-
-
Save ddribin/134567 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Summary: | |
The managed object context does not receive NSEditorRegistration notifications when binding the underlying array controller's content set. | |
Steps to Reproduce: | |
Using the attached MyTunes project: | |
1. Add an album | |
2. Add a song | |
3. Edit the song's name | |
4. Click the "Commit MOC" button | |
5. Check the "Bind to self" checkbox | |
6. Edit the song's name again | |
7. Click the "Commit MOC" button | |
Expected Results: | |
The in-process edit in Step 3 is committed when the button is pressed in Step 4 and the in-process edit in Step 6 is committed when the button is pressed in Step. 7. | |
Actual Results: | |
The edit does not get committed in Step 7. | |
Regression: | |
This does not work on any version of Mac OS X 10.5, and does not work on 10.6 (tested on 10A380). | |
Notes: | |
When "Bind to self" is unchecked, the Songs array controller's content is bound to the selection of the Albums array controller. When it is checked, it is bound to the "selectedAlbum" property of the document. For some reason, binding directly to the document (or through an NSObjecController proxy) does not cause the MOC to get the NSEditorRegistration methods. | |
While it is possible to commit editing directly on the Songs array controller or using [window makeFirstResponder:window], neither of these solutions very robust. | |
The best workaround is to implement objectDidBegin/EndEditing: in the document, and pass those down to the MOC. This way, we can always call commitEditing: on the MOC when we need to ensure UI edits are complete before proceeding. | |
- (void)objectDidBeginEditing:(id)editor | |
{ | |
[[self managedObjectContext] objectDidBeginEditing:editor]; | |
if ([[MyDocument superclass] instancesRespondToSelector:@selector(objectDidBeginEditing:)]) { | |
[super objectDidBeginEditing:editor]; | |
} | |
} | |
- (void)objectDidEndEditing:(id)editor | |
{ | |
[[self managedObjectContext] objectDidEndEditing:editor]; | |
if ([[MyDocument superclass] instancesRespondToSelector:@selector(objectDidEndEditing:)]) { | |
[super objectDidEndEditing:editor]; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment