我在打开包含空格的目录时遇到问题。我的代码如下所示:
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseDirectories:YES];
if ( [openDlg runModal] == NSOKButton )
{
NSArray* files = [openDlg URLs];
NSString* directoryName = [[files objectAtIndex:0] absoluteString];
directoryURL = [files objectAtIndex:0];
NSLog(@"Directory Name: %@", directoryName);
NSArray *directoryArray = [directoryName componentsSeparatedByString:@"/"];
NSString* currentDirectory = [directoryArray objectAtIndex:(directoryArray.count- 2)];
[directoryBox setTitle:currentDirectory];
}
当我选择带有空格的目录名称时,文件不会显示在表格中,并且 NSLog 中的输出如下所示:
目录名称:
file://localhost/Users/Rich/Software%20Bisque/
有任何想法吗?