Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArrayController and takeValueForKey



Hello list,

here is my problem:
I use an ArrayController to manage an array of Dictionary-objects (the
array-controller's contentArray is itself bound to UserDefaultsController
btw); each dictionary contains a "file"-key.

Furthermore I bound a text-field to that file-key (precisely: bound to
"selection.file [arrController]"), so that I can edit the corresponding
value. It works like a charm if I type a value directly in the text-field,
but now I want to set it programmatically to the filename returned by a
NSOpenPanel-session. Here is what I wrote:
  ...
  NSArray filesToOpen = openPanel.filenames();
  String fileName = (String)filesToOpen.objectAtIndex(0);
  NSKeyValue.takeValueForKeyPath(arrController, fileName, "selection.file");
  ...
And here is the result:
  NSUnknownKeyException: [<_NSControllerObjectProxy 0x3f51b0>
  takeValue:forKey:]: attempt to assign value to unknown key: 'file'.
  This class does not have an instance variable of the name file or _file,
  nor a method of the name setFile, or _setFile
I also tried a couple of other variations:
  ((NSObject)localDictsController.selection()).takeValueForKey(fileName,
"file");
and
  ((NSObject)localDictsController.valueForKey("selection")).takeValueForKey(fileName,
"file")
with the same results. Finally I tried to do the same with Objective-C (in
a newly created test-project):
  [arrController setValue:fileName forKeyPath:@"selection.file"];
and it worked perfectly! But I've already written _a lot_ of code in java
and don't want to port everything to ObjC (did I mention that I like java
_much_ better?).

Did anyone run into the same problem? Does anyone have an idea how to
solve this issue?

Thanks in advance and best regards,
Markus


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.