Objective c 拖放操作不需要';不能使用NSBox的子类

Objective c 拖放操作不需要';不能使用NSBox的子类,objective-c,cocoa,drag-and-drop,subclass,nsdragginginfo,Objective C,Cocoa,Drag And Drop,Subclass,Nsdragginginfo,我已经创建了NSBox的一个子类来实现拖放。我有以下代码: @interface DropView : NSBox { } - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender; - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender; @end @implementation DropView - (void)awakeFromNib {

我已经创建了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
@接口DropView:NSBox{
}
-(NSDragOperation)拖动者:(id)发送者;
-(BOOL)performDragOperation:(id)发送方;
@结束
@实现DropView
-(无效)从NIB中唤醒
{
[自注册或碎片类型:
[NSArray arrayWithObject:NSFileNamesPardType]];
}
-(NSDragOperation)DragginGeted:(id)发送方
{
NSDRAGO操作源DRAGMASK=[发送方
拖动源操作掩码];
if(sourceDragMask和NSDragOperationLink){
返回NSDragOperationLink;
}else if(源DragMask和NSDragOperationCopy){
返回NSDRAGO操作副本;
}
返回nsdragooperationne;
}
-(BOOL)performDragOperation:(id)发送方
{
NSPasteboard*pboard=[发送方拖动粘贴板];
NSArray*文件=[pboard propertyListForType:NSFilenamesPboardType];
N分子*e=[files objectEnumerator];
NSString*str=nil;
而(str=[e nextObject]){
NSLog(@“Got%@\n”,str);
}
返回(真);
}
@结束
但是,拖放不起作用。当我试图把东西拖进盒子时,我看不到绿色的加号


谢谢

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