NSOpenPanel在以表格形式显示时不会打开,但在以模态方式运行时会打开

时间:2016-02-11 14:54:23

标签: objective-c cocoa appstore-sandbox nsopenpanel

我已打开App沙盒并勾选USB访问和用户选定文件(只读)。

当我尝试以模态方式打开NSOpenPanel时,它会打开

NSOpenPanel *openPanel = [NSOpenPanel openPanel];
NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"txt", nil];

[openPanel setAllowsMultipleSelection: NO];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanCreateDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setAllowedFileTypes:fileTypes];
[openPanel setDirectoryURL:[self getFileURL]];

 [openPanel beginWithCompletionHandler:^(NSInteger result){
    if (result == NSFileHandlingPanelOKButton) {
        NSURL*  selectedFileUrl = [[openPanel URLs] objectAtIndex:0];

    }

}];

这是以表格形式打开的代码:

[openPanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger result){
    if (result == NSFileHandlingPanelOKButton) {
        NSURL*  selectedFileUrl = [[openPanel URLs] objectAtIndex:0];
    }

}];

执行上述代码时没有任何反应。

  

NSURL是:file:///Volumes/SE23/documents/My%.File.txt

0 个答案:

没有答案