开发者

NSTableView Drop App File, Whats Going Wrong?

开发者 https://www.devze.com 2023-02-07 05:22 出处:网络
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 registerFor

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 registerForDrag开发者_如何学PythongedTypes: 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消