1
我試圖編寫一些簡單的代碼,將文本文件的內容拖放到窗口上。在前面的帖子和蘋果例子的幫助下,我現在已經掌握了拖放和運行的基礎知識。拖放粘貼板數據
不幸的是,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];
}
}
感謝:-)
謝謝,彼得。那麼如果我試圖爲文本文件(字符串類型的數據)提供一個文本文件而不是圖像文件,這種方法仍然可以不被修改嗎? – Bender 2010-01-11 01:17:05
閱讀並參閱。請求文本時它會做什麼? – 2010-01-11 01:26:23
在輸入此方法之前,您並未向數據板提供數據 - 這是此方法的工作。這種方法實現了你之前做出的承諾;當另一端嘗試訪問您承諾但未提供的數據時,您會收到此消息。 – 2010-01-11 01:28:34