Drag and drop not working with NSBox subclass

I created an NSBox subclass to implement drag and drop. I have the following code:

@interface DropView : NSBox {

}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
@end

@implementation DropView
- (void)awakeFromNib
{
    [self registerForDraggedTypes:
  [NSArray arrayWithObject: NSFilenamesPboardType]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
 NSDragOperation sourceDragMask = [sender 
           draggingSourceOperationMask];
 if (sourceDragMask & NSDragOperationLink) {
  return NSDragOperationLink;
 } else if (sourceDragMask & NSDragOperationCopy) {
  return NSDragOperationCopy;
 }
 return NSDragOperationNone;
}

-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
 NSPasteboard *pboard=[sender draggingPasteboard];
 NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
 NSEnumerator *e=[files objectEnumerator];
 NSString *str=nil;
 while(str=[e nextObject]) {
  NSLog(@"Got %@\n", str);
 }

 return (TRUE);
}
@end

      

However, drag and drop doesn't work. I don't see the green plus when I try to put something in a box.

thank

+2


source to share


1 answer


Fixed problem. Instead of setting NSView class to DropView, setting NSBox class to DropView worked fine :-)



+3


source







All Articles