2

我正在使用 NSOpenPanel 在我的应用程序上设置一个文件夹,但我将其作为文件夹“file://localhost/Users/juan/”的路径

这是我的代码:

    NSOpenPanel * setDirectory = [NSOpenPanel openPanel];
    setDirectory.canChooseFiles=NO;
    setDirectory.canCreateDirectories=YES;
    setDirectory.canChooseDirectories=YES;
    setDirectory.directoryURL=_path;
    [setDirectory beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
        NSLog(@" results %ld", result);
        if (NSFileHandlingPanelCancelButton){
            NSLog(@"cancel");

        }
        if (NSFileHandlingPanelOKButton) {

            self.path = [[setDirectory URLs] objectAtIndex:0];

        }

    }];
}

我的问题是如何或我需要做什么来获得绝对路径,例如“/Users/juan/Desktop/”而没有文件:// localhost。

我真的很感激任何指示。

4

2 回答 2

4

为此,请调用对象的path方法NSURL

于 2012-12-21T03:17:59.953 回答
1

我发现了我正在使用的问题[bitmapData writeToFile:nameandPath atomically:YES];,它给了我一个错误。
我切换到[bitmapData writeToURL:nameandPath atomically:YES];并且一切正常。

于 2012-12-21T19:35:47.100 回答