2

I have the following code to support dropping an app file into a table view. The problem is that I don't even see the green + when I drag and drop. I think it has something to do with the registerForDraggedTypes: but I'm not sure. I've tried many tutorials and none have worked for me.

- (void)awakeFromNib {
[apps registerForDraggedTypes:[NSArray arrayWithObject:@"app"]];    
}


- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes         toPasteboard:(NSPasteboard*)pboard
{
return YES;
}
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
{
return NSDragOperationCopy;
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
          row:(int)row dropOperation:(NSTableViewDropOperation)operation
{
return YES;
}

Thanks in advance

Jay
  • 6,572
  • 3
  • 37
  • 65
nosedive25
  • 2,477
  • 5
  • 30
  • 45

1 Answers1

2

registerForDraggedTypes isn't looking for an array of file extensions; it takes an array of uniform type identifiers. If you want to accept filenames, use the NSFilenamesPboardType:

 [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];

Then, to only accept .app files, check the extension and return YES from tableView:acceptDrop:row:dropOperation:, getting the appropriate information from the NSDraggingInfo and its pasteboard.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
kevingessner
  • 18,559
  • 5
  • 43
  • 63
  • For some reason I'm still not seeing the green +. What could be causing this? – nosedive25 Jan 29 '11 at 22:01
  • Check the obvious: is your IBOutlet for the table view hooked up? Is the table view delegate connected? Does a breakpoint or NSLog in `acceptDrop` get hit? – kevingessner Jan 29 '11 at 23:02
  • It was all hooked up but still not working. To get it to work I used your suggestion but put it in an invisible NSView on top of the table view. – nosedive25 Jan 30 '11 at 02:58