【发布时间】:2010-01-10 23:09:10
【问题描述】:
我正在尝试编写一些简单的代码来将 text 文件的内容拖放到窗口上。在之前的一篇文章和一个 Apple 示例的帮助下,我现在掌握了拖放操作的基础知识。
不幸的是,Apple 的示例代码只处理图像。谁能告诉我如何修改他们的“粘贴板”方法(如下所示)以发送简单的“dot.txt”文件的内容?
- (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type
{
//------------------------------------------------------
// method called by pasteboard to support promised drag types.
//--------------------------------------------------------
//sender has accepted the drag and now we need to send the data for the type we promised
if([type compare: NSTIFFPboardType]==NSOrderedSame)
{
//set data for TIFF type on the pasteboard as requested
[sender setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
}
else if([type compare: NSPDFPboardType]==NSOrderedSame)
{
[sender setData:[self dataWithPDFInsideRect:[self bounds]] forType:NSPDFPboardType];
}
}
谢谢:-)
【问题讨论】:
标签: cocoa drag-and-drop