Mailing Lists: Apple Mailing Lists

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

Re: How does a binding know what it gets should be treated like an NSArray or not ? (Follow up)




On 2006/02/26, at 10:44, email@hidden wrote:

On 2006/02/26, at 6:06, Camillo Lugaresi wrote:

In general, it looks like you're making things harder for you than they should be. It's not obvious why you would need a custom array controller for that UI. This site has several examples of the recommended way to do things: <http://homepage.mac.com/mmalc/ CocoaExamples/controllers.html>
Yes, your right, I was definitely making it much harder than it needed to be.

In fact, one of the first places I went to for pointers was the page you just mentioned (thanks to mmalc), but couldn't find the solution to my specific problem there either.

................

So it turns out, my solution was standing in front of me the whole time. Just let the proxy be a full proxy, not just for the derived key value, but all key values of the wrapped object, and return an array of managed objects wrapped in proxies from arrangedObjects. Then I can bind the table view to all the keys from the same base key path and get the results I wanted. It works perfectly.

I just wanted to follow up on myself, and post my discovery in case any one else using self-made proxies in an NSArrayController. (Yes, all 2 of you)


If one is going to wrap individual objects contained in an NSArrayController, do not return them from -(id)arrangedObjects.
If you do, you'll lose sorting for any key-values the proxy adds to the wrapped object. Sorting is done from -(NSArray *)arrangeObjects: (NSArray *)objects.


So in arrangeObjects, you wrap each object in the "objects" array, then pass that array to super's implementation of arrangeObjects and return the array.

Like so:

-(NSArray *)arrangeObjects:(NSArray *)objects
{
	//Objects in contents are now wrapped
	NSArray *wrappedObjects = [self wrapObjectsInProxiesFromArray:objects];

//Pass to super to let it sort using keys provided by other UI elements such as NSTableColumn
return [super arrangeObjects:wrappedObjects];
}


Chiao,

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

This email sent to email@hidden
References: 
 >Fwd: How does a binding know what it gets should be treated like an NSArray or not ? (Was: How to observe and bind (KVO/KVB) to a value generated at runtime..) (From: 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.