我正在尝试创建一个接受任何文件类型并将其上传到服务器(使用 ASIHTTPRequest)的拖放区域。我查看了 Apple 提供的以下示例:
http://developer.apple.com/library/mac/#samplecode/CocoaDragAndDrop/Introduction/Intro.html
但它只涉及处理图像的拖放。如何设置拖放操作以处理任何文件类型?
谢谢。
最佳答案
有点相关,但添加这个以防对某人有帮助:
如果您只想处理拖到应用程序图标上的任何文件(不需要是基于文档的应用程序):
在 .h 中:
- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames;
在 .m 中:
- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames {
NSLog(@"Files dragged on: %@", fileNames);
}
在您的 xxx.plist 中,在 CFBundleDocumentTypes 下创建一个新条目:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeName</key>
<string>NSFilenamesPboardType</string>
<key>CFBundleTypeRole</key>
<string>None</string>
</dict>
</array>
关于objective-c - Cocoa:拖放任何文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4356620/