registerForDraggedTypes with custom file formats

后端 未结 1 892
攒了一身酷
攒了一身酷 2021-02-06 15:58

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

1条回答
  •  北海茫月
    2021-02-06 16:48

    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;
    }
    

    0 讨论(0)
提交回复
热议问题