Pregunta

He creado una subclase de NSBox para implementar arrastrar y soltar. Tengo el siguiente código:

@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

Sin embargo, arrastrar y soltar no funciona. No veo el pequeño plus verde cuando trato de arrastrar algo a la caja.

Gracias

¿Fue útil?

Solución

Se solucionó el problema. En lugar de configurar la clase de un NSView en DropView, configurar la clase de un NSBox en DropView funcionó muy bien :-)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top