首页 文章

Cocoa:拖放任何文件类型

提问于
浏览
8

我正在尝试创建一个接受任何文件类型的拖放区域,并将其上传到服务器(使用ASIHTTPRequest) . 我查看了Apple提供的以下示例:

http://developer.apple.com/library/mac/#samplecode/CocoaDragAndDrop/Introduction/Intro.html

但它只涉及处理图像的拖放 . 如何设置拖放操作来处理任何文件类型?

谢谢 .

2 回答

  • 6

    从这个post判断,你可能只需要让你的视图注册 NSFilenamesPboardType 而不是 imagePastBoardTypes 来接收任意文件类型 .

  • 12

    有点相关,但添加这个以防它对某人有帮助:

    如果您只想处理拖动到应用程序图标上的任何文件(不需要是基于文档的应用程序):

    在.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>
    

相关问题