我已经创建了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但是,拖放不起作用。当我试图把东西拖到盒子里时,我看不到绿色的小加号。
谢谢
发布于 2009-09-17 00:53:53
已修复此问题。没有将NSView的类设置为DropView,而是将NSBox的类设置为DropView :-)
https://stackoverflow.com/questions/1436175
复制相似问题