NSOpenPanel 使用(MAC 打开文件夹对话框的使用)
NSOpenPanel 使用(MAC 打开文件夹对话框的使用)
1.得到多个选择的文件
2.指定文件类型
-(NSString *)get_fullpath
{
NSOpenPanel *panel = [NSOpenPanelopenPanel];
NSArray* fileTypes = [[NSArrayalloc] initWithObjects:@"txt",@"doc", nil];
[panel setMessage:@"select a file"];
[panel setPrompt:@"OK"];
[panel setCanChooseDirectories:NO];
[panel setCanCreateDirectories:YES];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:YES];
[panel setAllowedFileTypes:fileTypes];
NSString *path_all=@"";
NSArray *select_files;
NSInteger result = [panel runModal];
m_LB1.stringValue =@"";
if (result ==NSFileHandlingPanelOKButton)
{
select_files = [panel filenames] ;
for (int i=0; i<select_files.count; i++)
{
path_all= [select_files objectAtIndex:i];
m_LB1.stringValue = [m_LB1.stringValuestringByAppendingString:path_all];
m_LB1.stringValue = [m_LB1.stringValuestringByAppendingString:@"\n"];
NSLog(path_all);
}
}
return @"";
}
@end
以上在XCODE 4.6上 通过!