• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another)


  • Subject: Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another)
  • From: アンドレ(Andre) <email@hidden>
  • Date: Sun, 6 Feb 2005 18:04:45 -0800

Note that arrangedObjects and selectedObjects are arrays (also for a single selection), not the selected object itself. You should use
Controller Key: selection
Model Key Path: columns
Just did it, and it all works now.
But I don't understand what is the difference between
selection and selectedObjects/arrangedObjects?

I think this is maybe why some people want a bindings book (maybe better a coredata book)
because while there is a lot of documentation, its a little assuming we already know 'certain' things....
If someone could explain everything in a more detailed and bottom-up way it might be nice....


In any case, thanks a lot for your help!

I appreciate it.


On 平成 17/02/06, at 1:42, Christiaan Hofman wrote:



On Feb 6, 2005, at 10:49, アンドレ(Andre) wrote:

The first ArrayController controls the first array, so the 'add' method adds an instance of object1 to the array, while it allows you to select a particular object1 (the selection). Now you want to add an object2 to the array in selected object1. Do I understand you correctly?
Yes this is exactly it.


If so, what you need to do is to bind the content of the second NSArrayController to the selection of the first NSArrayController, with the model keypath given by the key for the array which contains the object2-s (which is columns, if I understand your example).
I actually tried something similar, I bound the content of the controller2 to the selection.columns of the
first one. but I still had problems because the console output said something about the returned object
not being compliant...


Heres my binding for the second controller to the first:
<Picture 2.png>I tried selectedObjects but got errors too....


Note that arrangedObjects and selectedObjects are arrays (also for a single selection), not the selected object itself. You should use
Controller Key: selection
Model Key Path: columns


For this part, it should work, at least it does for me. If there is still an error, I guess it is at another stage.

You should implement KVC array accessors in object1, like insertObject:inColumnsAtIndex:. Then -add: of the second NSArrayController adds an object2 to the columns array of the selected object1.
I see what your saying. I'll go ahead and implement that and see what happens... though I'm a little
lost as to WHAT exactly I should do in this method... I've read just about everything, but the stuff
about bindings (especially through IB) makes everything seem almost all automatic... especially the
stuff thats coming...


I follow your suggestion!

Though shouldn't the NSArrayController know how to handle all those things if I had my object
and one of its variables is an NSArray?


I think so. However it is always best to implement the KVC compliant array accessors, which in your case probably just echo anything to the columns array. So do things like

- (id)objectInColumnsAtIndex:(unsigned int)index {
    [columns objectAtIndex:index];
}

See the documentation on which KVC methods to implement (they are basically the same as the array accessors with "InColumns" added, or whatever the name is).

Also, make sure that the Object Class Name of the arraycontrollers is set to the class in your array (but this is only relevant for adding though).

Christiaan


_______________________________________________
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


  • Follow-Ups:
    • Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another)
      • From: mmalcolm crawford <email@hidden>
References: 
 >NS(Array)Controller and To-Many Relationships (how to add objects from one to another) (From: アンドレ(Andre) <email@hidden>)
 >Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another) (From: アンドレ(Andre) <email@hidden>)

  • Prev by Date: Re: Switch between multiple views
  • Next by Date: Re: Memory Managment (copys??)
  • Previous by thread: Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another)
  • Next by thread: Re: NS(Array)Controller and To-Many Relationships (how to add objectsfrom one to another)
  • Index(es):
    • Date
    • Thread