NSOpenPanel 设置允许打开的文件类型

来源:互联网 发布:是焉得为大丈夫乎的得 编辑:程序博客网 时间:2024/05/15 00:58

 couple things I noticed.. change setCanChooseDirectoriesto NO. When enabled this indicates that folders are valid input. This is most likely not the functionality you want. You might also want to change your allowed file types to [NSArray arrayWithObject:@"pdf", @"PDF", nil] for case sensitive systems. runModalForTypes should be the array of file types. Change your code to look like this:

// WORKING :)NSOpenPanel *panel;NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"pdf", @"PDF", nil];panel = [NSOpenPanel openPanel];[panel setFloatingPanel:YES];[panel setCanChooseDirectories:NO];[panel setCanChooseFiles:YES];[panel setAllowsMultipleSelection:YES];[panel setAllowedFileTypes:fileTypes];int i = [panel runModal];if(i == NSOKButton){    return [panel URLs];}
0 0
原创粉丝点击