Skip navigation.
 
mlRE: Help with NSArrayController, NSTableView and NSOpenPanel
FROM : Kamrin Dahlin
DATE : Fri Jun 23 17:33:56 2006

Hey George,

Thanks for all of your help.

I will dig into the Cocoa Bindings article today.  I started reading it last night, but didn't make it as far as the link you provided.  Could you maybe answer one more question for me.

If I have an existing array of objects and I want to display each one of the objects in the array on its own row of my table, how can I make this happen via bindings?  My application is setup with a model that will be used for other things, so having the array of directoryContents inside of each of my DirectoryModel objects is needed.  I have the NSArrayController managing the DirectoryModel objects now, but I am not sure how to make a second table display the individual values of my DirectoryModels directoryContents array.  I have tried hooking it up to its own NSArrayController, but end up with a single row of all of the values.

Hopefully that makes sense.

And again, you have been a huge help and I really appreciate it.

thx

k

-----Original Message-----
From: George Orthwein [mailto:george.<email_removed>]
Sent: Fri 6/23/2006 6:45 AM
To: Kamrin Dahlin
Cc: <email_removed>
Subject: Re: Help with NSArrayController, NSTableView and NSOpenPanel

On Jun 22, 2006, at 10:50 PM, Kamrin Dahlin wrote:
> I guess i was under the impression that the NSArrayController would 
> automatically get these changes to my Directory model class and i 
> wouldn't need to make this call programmatically?  I guess I don't 
> really get how bindings are supposed to work.  Shouldn't KVO be at 
> work every time one of my DirectoryModels is created and changed?


I wasn't too sure about this either but I guess not. From 
"Programmatically Modifying a Controller's Contents":
http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Concepts/CntrlContent.html

"The addObject: and removeObject: methods have somewhat different 
behavior for NSArrayController. In this case their behavior is the 
same as NSArray's addObject: and removeObject: methods. Unlike 
NSArray's implementations, these methods inform the array controller 
of the changes so that they can be reflected in the user interface."

I did a test with cocoadevcentral's MailDemo example. When the 
Mailbox NSArrayController was bound directly to the mutable array 
ivar in MyController through the contentArray binding... I had to 
call rearrangeObjects on the arrayController for it to recognize a 
change in the ivar. That's why he adds the NSObjectController 
"ControllerAlias". As he puts it, it's the bridge to the bindings 
system for MyController. Again, a simpler setup is to ditch the ivar, 
the contentArray binding and the NSObjectController and just let a 
single NSArrayController manage the objects itself.

Also, don't forget you can just call add: on the NSArrayController 
for a new object. It inherits the methods of its superclass 
NSObjectController.

The link above has a lot of good stuff in it. Check it out. :)

George

Related mailsAuthorDate
mlHelp with NSArrayController, NSTableView and NSOpenPanel Kam Dahlin Jun 22, 22:43
mlRe: Help with NSArrayController, NSTableView and NSOpenPanel George Orthwein Jun 23, 04:31
mlRE: Help with NSArrayController, NSTableView and NSOpenPanel Kamrin Dahlin Jun 23, 04:50
mlRe: Help with NSArrayController, NSTableView and NSOpenPanel George Orthwein Jun 23, 15:45
mlRE: Help with NSArrayController, NSTableView and NSOpenPanel Kamrin Dahlin Jun 23, 17:33
mlRe: Help with NSArrayController, NSTableView and NSOpenPanel George Orthwein Jun 23, 20:47
mlRE: Help with NSArrayController, NSTableView and NSOpenPanel Kamrin Dahlin Jun 23, 20:51
mlRE: Help with NSArrayController, NSTableView and NSOpenPanel Kamrin Dahlin Jun 23, 23:58
mlRe: Help with NSArrayController, NSTableView and NSOpenPanel Kam Dahlin Jun 24, 01:15
mlRe: Help with NSArrayController, NSTableView and NSOpenPanel Scott Anguish Jun 24, 08:20