2009-09-17 71 views
2

我已经创建了NSBox的子类来实现拖放操作。我有以下代码:拖放不适用于NSBox的子类

@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 

但是,拖放不起作用。当我尝试将某些东西拖入盒子时,我看不到绿色加上。

谢谢

回答

3

解决了这个问题。而不是将NSView的类设置为DropView,将NSBox的类设置为DropView效果很好:-)