Skip navigation.
 
mlRe: wiring up core data, bindings, NSArrayController and NSCollectionView
FROM : Philip Bridson
DATE : Tue Feb 26 20:23:17 2008

Hi there, I am no expert on core data but I have been using it 
extensively in my app over the past few months. From what I can see 
from your code it looks similar to what I have been doing and it 
works fine for me to be honest. What I think maybe the problem is 
that just because you have bound the tables values to the array 
controller does not mean you can just instantly add/remove things 
from it. You need to connect (not bind) a button of some sorts to the 
array controller which will give you the ability to add/remove/
select. To be honest I am not to sure about implementing drag and 
drop in core data and I cannot find reference to it in the core data 
documentation. I hope this helps, if it does not I am sorry.

Phil.

On 26 Feb 2008, at 19:09, Knud Hinnerk Möller wrote:

> Hi,
>
> I'm a little confused about a setup involving core data, bindings, 
> NSArrayControllers and an NSCollectionView. Things were fine before 
> I used core data:
>
> - I have an NSCollectionView, where each view item represents a 
> KNBox, which contains a list of KNDesktopThings, represented by a 
> table
> - I have subclassed NSCollectionView, so that each view item 
> receives its own NSArrayController, to which I bind the table
> - I have also subclassed NSCollectionViewItem and made each item 
> the datasource of its table to implement drag and drop for the table
> - before using core data, each view item would accept a drop, 
> create a new thing and add it to the array controller
> - this worked perfectly
>
> Now, with core data, things are a bit different:
>
> - I have a data model with boxes and things. Things are related to 
> boxes via a "boxItems" relation
> - here is how I set up the array controller (beware, this is 
> CocoaRuby):
>
>    arrayController.setEntityName("KNDesktopThing")
>    arrayController.setContent(box.boxItems)
>
> - here is what I do when I accept a drop and want to create a new 
> thing:
>
>    managedObjectContext = NSApp.delegate.managedObjectContext
>    newThing = 
> NSEntityDescription.insertNewObjectForEntityForName_inManagedObjectCon
> text("KNDesktopThing", managedObjectContext)
>    box.addBoxItemsObject(newThing)
>    arrayController.setContent(box.boxItems)
>
> This works, but especially the last two lines make me wonder if I'm 
> not doing things the wrong way here. Is there a way I can set 
> things up so that I either:
>
> - only add the new thing to the arrayController, which would 
> hopefully update the relation, or
> - only add the new thing to the relation, which would hopefully 
> update the array controller.
>
> Why do I want to use core data? Because I hope it will give me 
> "free" saving and undo.
>
> Cheers,
> Knud
>
> -------------------------------------------------
> Knud Möller, MA
> +353 - 91 - 495086
> Smile Group: http://smile.deri.ie
> Digital Enterprise Research Institute
>  National University of Ireland, Galway
> Institiúid Taighde na Fiontraíochta Digití
>  Ollscoil na hÉireann, Gaillimh
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/philipleebridson%
> 40mac.com
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlwiring up core data, bindings, NSArrayController and NSCollectionView Knud Hinnerk Mölle… Feb 26, 20:09
mlRe: wiring up core data, bindings, NSArrayController and NSCollectionView Philip Bridson Feb 26, 20:23