在nsviewcontroller中实现拖放

时间:2017-01-25 11:50:42

标签: objective-c macos drag-and-drop

我正试图在nsviewcontroller中捕捉拖放事件,但是

  

draggingEntered

未被调用。

这是我的代码:

- (void)viewDidLoad {
[self.view registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, NSFilenamesPboardType, nil]];

[super viewDidLoad];

// Do any additional setup after loading the view.
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
    return NSDragOperationCopy;
}

- (BOOL)prepareForDragOperation:(id )sender {
    return YES;
}

我添加了自定义视图,但它也没有获得事件:

   @implementation MyView
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self registerForDraggedTypes:[NSArray arrayWithObjects: NSColorPboardType, NSFilenamesPboardType, nil]];
    }
    return self;
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {

    return NSDragOperationNone;
}

@end

0 个答案:

没有答案