我正在用可可开发一个flvplayer.我想从finder拖动一个flv文件并将其放到webview窗口(我用它来查看flv).但我没有找到这个文件的路径.这是我的代码:
_ (void)showflv(nsstring*)aa
{
..........
//Register to accept flv drag/drop
NSString *pboardType = NSCreateFileContentsPboardType(@"flv");
NSArray *dragTypes = [NSArray arrayWithObject:pboardType];
[self registerForDraggedTypes:dragTypes];
}
_ (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFileContentsPboardType] ) {
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我阅读了有关this的文档.我发现PerformDragOperation的功能可以这样写:
_ (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFileContentsPboardType] ) {
NSFileWrapper *fileContents = [pboard readFileWrapper];
// Perform operation using the file’s contents
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我可以得到这个拖动文件的文件内容.但是如何获取路径?
NSString *fileName = [fileContents filename];
Run Code Online (Sandbox Code Playgroud)
我做了一个测试,这是不正确的.
我做了一个测试,但是draggedFilePaths没有用.我发现代码:
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFileContentsPboardType] ) {
//NSFileWrapper *fileContents = [pboard readFileWrapper];
// Perform operation using the file’s contents
nslog(@"aa");
}
Run Code Online (Sandbox Code Playgroud)
当应用程序运行时,字符串"aa"没有出现,为什么?
像这样:
NSArray *draggedFilePaths = [pboard propertyListForType:NSFilenamesPboardType];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2486 次 |
| 最近记录: |