2

The old way was [ MyPanel runModalForDirectory: thedir file: thefile ], and the panel would open in the specified directory with the specified file already selected.

That's deprecated; we're supposed to use runModal now, but I don't see any way to set the selected file name. I've tried including it in the string for setDirectoryURL, I've tried setRepresentedFilename, I've tried setNameFieldStringValue ... obviously it's possible to do this somehow, but I'm not having any luck with the internet search terms I've chosen, nor with Apple's documentation....

Thanks if you can help!

4

1 回答 1

1

文档列出了setDirectoryURL:&setNameFieldStringValue:在 10.6 及更高版本中可用:

NSString *defaultDirectoryPath, *defaultName;
NSOpenPanel *openPanel;
...
[openPanel setNameFieldStringValue:defaultName];
[openPanel setDirectoryURL:[NSURL fileURLWithPath:defaultDirectoryPath]];
[openPanel runModal];
于 2012-05-14T20:51:51.157 回答