cappuccino

Cappuccino Drag and Drop Error


I'm trying to implement drag and drop in cappuccino but keep getting an error when i drop an image on a CPView, i copied the error message from console below.

CPInvalidArgumentException: - [CPImage removeFromSuperview] unrecognized selector sent to instance 0x0051bd

I'm dragging an image from CPCollectionView which is contained inside a CPScrollView and dropping it on a CPView. I followed the example from the ScrapBook tutorial.

Below is the code on my CPView for dropping, this code causes the output from the console

- (void)performDragOperation:(CPDraggingInfo)aSender
{
    var data = [[aSender draggingPasteboard] dataForType:PhotoDragType];
    [self addSubview:[CPKeyedUnarchiver unarchiveObjectWithData:data]];
}

I defined my drag type in my AppController.j since my CPScrollView is defined their, don't know if this is causing the issue.

Thanks.


Solution

  • What's in the drag and drop pasteboard is NOT the view, it's the representedObject of the collection view item. (In your case a CPImage object).

    The solution here is to create a new CPImageView and add it to the drop view, then set the image of that image view to the pasteboard data (assuming it's always an image).