small medium large xlarge

Back to: All Forums  Core Data
Paul54729_pragsmall
28 Oct 2010, 21:32
Paul Johnson (21 posts)

I have been trying to get drag and drop working to copy from one tableview to another in the same application. Each table view uses Core Data to obtain its data.

I used the Data Modeler to create two models, one for the data in each tableview.

The model for the data in the destination tableview is essentially the same as for the source tableview. The only difference is that the data model for the destination tableview has an additional entity and a relationship.

Both tableviews display 3 columns of data, which are NSStrings.

When I drag and drop, I simply want to copy the selected rows (each containing 3 strings).

Right now I’m getting an error message when I try to decode the pasteboard data: “Failed to call designated initializer on NSManagedObject class ‘Market’”

I guess I can write more code and just copy the strings to build an array that doesn’t depend on “NSManagedObject”, but perhaps someone can help me avoid doing this, but instead recommend a method makes drag and drop compatible with Core Data.

Avatarsmall_pragsmall
28 Oct 2010, 21:43
Marcus S. Zarra (284 posts)

Core Data entities can’t be just dragged and dropped from each other. You must create a new MO in the destination and copy the data into it. I suspect that is the source of your error.

Paul54729_pragsmall
30 Oct 2010, 14:49
Paul Johnson (21 posts)

Yes, Marcus, that was the problem.

One addition difficulty remains, and perhaps you can point me in the right direction. The destination tableview contains 3 NSStrings for each row, and I can now set them up properly. However, the entity also has a Relationship that I need to initialize. It’s a pointer to the selected item in another table in the window. How do I set this Relationship up?

And it appears I also need to call some method to tell Core Data what I’ve added. And perhaps call a method to refresh the window display. (I’m using bindings so perhaps the updating of the window can be automated with bindings.)

(I may not be using the correct terminology here as I’m somewhat new to this, as you can tell.)

Avatarsmall_pragsmall
30 Oct 2010, 15:58
Marcus S. Zarra (284 posts)

Since relationships do not carry over either, you need to find another way to uniquely bind to that table and its row and then re-create the relationship in the new MO.

Once you add everything into your Core Data repository, your bindings should see it all and update your views.

Generic-user-small
17 Feb 2011, 08:04
Andrew Greaney (4 posts)

Hey Paul,

did you manage to drag n drop between tableviews?

I can get it to work with an Entity which has no parents or children, but am having trouble creating the data in an Entity which has a parent.

Do you have any suggestions?

Paul54729_pragsmall
07 Sep 2011, 14:55
Paul Johnson (21 posts)

I didn’t see this until just today. Sorry. I assume you long ago solved the problem you were having. Yes, I did get drag-and-drop between tables to work. None of my Entities have a parent or children so I am unable to offer anything.

You must be logged in to comment