2013-05-29 43 views
0

我有一個NBox的子類,我想拖動一個名爲dragBox的畫布。我不明白爲什麼draggingEntry沒有被觸發在下面的代碼。我得到了一個很好的回退圖像,但沒有任何目標代表被解僱。爲什麼?draggingEntered not firing

-(void) awakeFromNib 
{ 
    [[self superview] registerForDraggedTypes:[NSArray  arrayWithObject:NSFilenamesPboardType]]; 


} 
-(void) mouseDown:(NSEvent *)theEvent 
{ 
    [self dragImage:[[NSImage alloc] initWithContentsOfFile:@"/Users/bruce/Desktop/Untitled-1.png"] at:NSMakePoint(32, 32) offset:NSMakeSize(0,0) event:theEvent pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] source:self slideBack:YES]; 




} 
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender // validate 
{ 
NSLog(@"Updated"); 
return [sender draggingSourceOperationMask]; 

} 

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { 
NSLog(@"Drag Entered"); 

return [sender draggingSourceOperationMask]; 

} 
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { 

NSLog(@"Move Box"); 
[self setFrameOrigin:[sender draggingLocation]]; 


    return YES; 
} 

-(BOOL) prepareForDragOperation:(id<NSDraggingInfo>)sender 
{NSLog(@"Prepared"); 
return YES; 

} 
+0

NBox ...什麼是NBox?的Xbox? NSImageView? –

回答

0

在您的mouseDown方法中,在啓動拖動操作之前,您沒有將任何東西放入紙板。 NSView的documentation表示您需要先將數據添加到粘貼板,然後再將其發送到該消息。

無論您有哪些目的地視圖,或者應該註冊某種拖動類型。如果您的粘貼板沒有該類型的任何匹配數據,則目標不會觸發任何NSDraggingProtocol消息。

+0

你好,我試圖在調用dragImage之前設置一個NSStringPboardType。它沒有工作。仍然沒有事件被解僱。 – bc888

0

解決!

我正在使用NSBox作爲目標和源。在這種情況下,事件並未被解僱。我將registerDragTypes移到了superview,畫布上,並在那裏實現了draggingEntered和performDrag。它現在的作品...

布魯斯

+0

我打算對此發表評論,但我假設你正在將你的NSBox的實例拖到其他可以工作的NSBox實例上。 :/ –