registerForDraggedTypes与自定义文件格式 [英] registerForDraggedTypes with custom file formats

查看:617
本文介绍了registerForDraggedTypes与自定义文件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发人员文档并未完全说明registerForDraggedTypes方法。例如,我想我的应用程序只允许访问* .abc文件。

Developer Documentations doesn't provides fully describe of registerForDraggedTypes method. For example, i want that my app allow access only "*.abc" files. How can i do this?

推荐答案

如果你想把文件拖到你的视图,你应该注册 NSFilenamesPboardType 类型。如果你只想接受某些文件名,你可以在你的实现 performDragOperation:。类似:

If you'd like to have files dragged onto your view, your should register for the NSFilenamesPboardType type. If you want accept only certain filenames, you can do that in your implementation of performDragOperation:. Something like:

- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender {
    NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
    if ([[[draggedFilenames objectAtIndex:0] pathExtension] isEqual:@"abc"])
        return YES;
    else
        return NO;
}

这篇关于registerForDraggedTypes与自定义文件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆