Desperate about NSArrayController (pullDown problems, changing a property of an object in the array programmatically)
Desperate about NSArrayController (pullDown problems, changing a property of an object in the array programmatically)
- Subject: Desperate about NSArrayController (pullDown problems, changing a property of an object in the array programmatically)
- From: John Clayton <email@hidden>
- Date: Sat, 02 Oct 2004 12:25:57 -0400
Hi Everybody,
So I decided to try to use NSArrayController to manage my interface, composed of a pullDown and a set of fields, etc. that display the properties of the selected object. I have a custom object managing the array (not File's Owner) and have implemented the necessary KVO methods to access the array as mutable data. The pullDown is bound via "content=arrangedObjects", "contentValues=arrangedObjects.name", and "selectedIndex=selectionIndex" to my array controller (though this last has to be done programmatically, which I'll explain later). "contentValues" inserts a nil placeholder. Basically, it works, the pullDown selection changes the array controllers selected object, and updates the display. The pullDown displays
But, I've run into two problems that I cannot seem to solve, though I've scoured this list and read over the documentation on bindings many times. Perhaps I just have some fundamental misunderstanding of how bindings work. I sure would appreciate some help.
Problem One
When the pullDown selectedIndex is bound to the array controller's selectionIndex a number of issues arise. If the array has no elements, the pullDown title displays 2147483647 instead of nothing or the nil placeholder value I set in the contentValues binding. I have managed to work around this by setting unsetting the binding when the array passes the 1 element boundary:
if([myArray count] > 0) {
[myObjectSelector bind: @"selectedIndex" toObject: myArrayController
withKeyPath:@"selectionIndex" options:nil];
}
I have no clue where this is coming from , except that this is the unsigned representation of -1, which I gleaned from this list. So, to bind the selection to other aspects of my interface (hidden, for a box, for example) I had to write a transformer which recognizes that value as no selection. This works, but now I've hit a dead-end. When I select the nil placeholder, this message gets logged: "[<NSArrayController 0x33d170> setNilValueForKey]: could not set nil as the value for the key selectionIndex." and the bound views do not update (hide, disable, etc..). If this can't be set then I guess I can use a traditional target/action method to make the updates, but then what's the point of the controller at all?
Problem Two
The array contains objects that represent processes on the machine, and so these can be changed in ways that don't involve the interface. Ok, I have tried ten different ways of making changes to these objects and getting the array controller to notice. Here's a small taste of the kinds of things I've been trying:
int idx = [myArray indexOfObject:myObject];
myObject = [myArray objectAtIndex:idx];
//[self willChangeValueForKey:@"myArray"];
//[myObject setStatusText:@"Running"];
[myObject setValue:@"Running" forKey:@"statusText"];
//[self didChangeValueForKey:@"myArray"];
//[self didChange:NSKeyValueChangeReplacement valuesAtIndexes:idx forKey:@"myArray"];
//[myArrayController rearrangeObjects];
//[self replaceObjectInMyArrayAtIndex:idx withObject:myObject];
I also tried sending notifications from within the accessor methods of myObject and some other things, like trying to change the value in the object through the array controller. Things I haven't tried include seeing if I can bind the array controller to values in each object in the array, this seems impossible to manage—constantly adding removing bindings and seems to defeat the whole purpose of bindings.
Does the need to modify the objects in the array programmatically mean using an array controller is inappropriate?
Well, I sure hope someone out there understands what I'm talking about, it's hard to explain as well as figure out ;-)
Thanks in advance for your help,
John Clayton
------------------------------------------------------------------------------
http://libcvs.cvshome.org/ Access CVS through a library.
------------------------------------------------------------------------------
"The stars are projectors."
- Modest Mouse _______________________________________________
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