0
votes

Okay, I've got a custom class called "Task", which represents a task to be done. I've got an NSMatrix which acts as a calendar. I want the user to be able to drag an icon from an nscollectionview (I've had no trouble setting up the nscollectionview) onto a cell in the nsmatrix, thereby assigning that task to that day. I just can't seem to get the nsmatrix to respond to the drag or the drop at all.

I've implemented the method:

- (BOOL)collectionView:(NSCollectionView *)cv writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard
{
    [pasteboard declareTypes:[NSArray arrayWithObject:TASK_UTI]  owner:self];
    NSUInteger index=[indexes firstIndex];
    Task* task=[[cv content] objectAtIndex:index];
    NSData* taskData=[NSKeyedArchiver archivedDataWithRootObject:task];
    [taskData retain];
    BOOL success=[pasteboard setData:taskData forType:TASK_UTI];

    return success;
}

in my nscollectionview delegate as shown above. I've sent [self registerForDraggedTypes:[NSArray arrayWithObjects:TASK_UTI, nil]] in my NSMatrix subclass (called "Calendar"). I've implemented the methods:

- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender

in my Calendar (NSMatrix subclass) class.

Some debugging shows that the NSMatrix/Calendar object is not even running the dragging methods above. What gives?

2
“I've sent [self registerForDraggedTypes:[NSArray arrayWithObjects:TASK_UTI, nil]] in my NSMatrix subclass…” Are you sure about that? What method did you send it from? Did you use NSLog to prove that that code ran?Peter Hosey
I ran it in the -awakeFromNib method, and yes, i ran NSLog Code: NSLog(@"Registered Drag types:%@", [[self registeredDraggedTypes] description]); With this result: 2010-01-11 18:54:59.963 Planner[48548:a0f] Registered Drag types:( "com.yourcompany.YGPlannerTask" )Joe Atkin

2 Answers

0
votes

Did you define your Calendar class to implement dragging destination protocol?

0
votes

First off, you should use your own domain name, not “com.yourcompany”, in the UTI.

Second, did you export the UTI in your Info.plist?