繁体   English   中英

使用NSOpenPanel获取文件夹位置删除file:// localhost

[英]using NSOpenPanel to get folder location remove file://localhost

我正在使用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];

        }

    }];
}

我的问题是在没有file:// localhost的情况下获取绝对路径(例如“ / Users / juan / Desktop /”)的方式或方法。

我真的很感谢任何指示。

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

我发现我正在使用[bitmapData writeToFile:nameandPath atomically:YES]; 这给了我一个错误。
我切换到[bitmapData writeToURL:nameandPath atomically:YES]; 一切运行正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM