打开openPanel的代码

- (IBAction)openPDFFile:(id)sender {

    NSOpenPanel *panel = [NSOpenPanel openPanel];

    [panel setAllowsMultipleSelection:YES];

    NSArray* fileArray = [NSArray arrayWithObjects:@"pdf", nil];

    [panel setAllowedFileTypes:fileArray];

    

    [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {

        if (result == NSOKButton)

        {

            [panel close];

            NSWindow *keyWindow = [NSApplication sharedApplication].keyWindow;

            if (self.window == keyWindow) {

                [[self homeViewCtrl].collectionView addItemsWithURLs:[panel URLs]];

            }

        }

    }];    

}

原文地址:https://www.cnblogs.com/PJXWang/p/5816630.html