星五博客

osx下选择文件并打印清单(NSOpenPanel)

NSOpenPanel* openDlg = [NSOpenPanel openPanel];
    //允许选择多文件
    [openDlg setAllowsMultipleSelection:YES];
    //允许选择文件
    [openDlg setCanChooseFiles:YES];
    //允许选择目录
    [openDlg setCanChooseDirectories:NO];
    //选择按钮的显示内容
    [openDlg setPrompt:@"选择文件"];
    //指定扩展名
    openDlg.allowedFileTypes = @[@"jpg",@"jpeg",@"png"];

    if ( [openDlg runModal] == NSModalResponseOK )
    {
        NSArray* files = [openDlg URLs];
        for( int i = 0; i < [files count]; i++ )
        {
            NSURL* fileName = [files objectAtIndex:i];
            NSLog(@"file %i : %@",i,fileName.path);
        }
    }


IOS