NSOpenPanel 使用(MAC 打开文件夹对话框的使用)

时间:2014-10-27 10:54:44   收藏:0   阅读:1859

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上 通过!



评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!