ドラッグアンドドロップを実装するために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
ただし、ドラッグアンドドロップは機能しません。ボックスに何かをドラッグしようとすると、小さな緑色のプラスが表示されません。
ありがとう