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
但是,拖放不起作用。當我嘗試將某些東西拖入盒子時,我看不到綠色加上。
謝謝