Re: IndexOfObject and bindings
Re: IndexOfObject and bindings
- Subject: Re: IndexOfObject and bindings
- From: Julien Palmas <email@hidden>
- Date: Thu, 24 Mar 2005 11:07:39 +0900
I have sub-classed NSArrayController but as still don't feel really at ease with the binding mechanism, I have some troubles implementing the solution you suggested in your precedent mail.
The thing is that I don't clearly understand how a NSArrayController does its job. For example, imagine that I have an array of "Person". Each of them have an attribute called name
- (NSString *)name;
If bind a column of a NSTableView to this attribute, the binding method will be :
bind:@"value" toObject:@"myController" withKeyPath:@"arrangedObjects.name" options:nil
KeyvalueCoding takes the keyPath, gets the object of the first value, then the second, and so on ....
So in this case, we will have
[[myController arrangedObjects] name]
but how can that be ???
[myController arrangedObjects] is supposed to be a NSArray, how come it would answer to the method "name" ? there must be a moment when the NSArrayController take an object of the array one after another and passes the method "name" .....
I am pretty confused ....
On Mar 23, 2005, at 9:10 PM, Nicko van Someren wrote:
On 23 Mar 2005, at 05:21, Julien Palmas wrote:
I want to bind one of the columns of my NSTableView with the index of the objects inside the array. To get a column that would display no more than 0, 1, 2, ....
I can't seem to find how to do it.
Is that something obvious or is that more complex ?
Bindings generally allow you to make use of attributes of the bound objects. Since objects in an array don't by default know that they are in the array (the array only references them, so they could perfectly be in more than one array) the position of the object in the array is not really an attribute of the object, so there is no way to get this information directly from the arranged objects of an NSArrayController.
I can see several ways to do what you need. Probably the most general way would be to sub-class NSArrayController to track the sorting of objects and have a new key of arrangedObjectIndices: which would return an array of NSNumbers identifying which object in the source array landed in a given position in the arranged array. This requires a moderate amount of work to implement. The quick and dirty solution would of course be to add an index attribute to the objects in the source array and then simply bind to that attribute in the table view.
Nicko
_______________________________________________
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