本文介绍了如何在NSSavePanel中预设文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSSavePanel以前具有runModalForDirectory:file:方法,该方法可让您预设保存面板的目录和文件名.但这在10.6中已弃用

NSSavePanel used to have a runModalForDirectory:file: method which let you preset the directory and filename for a save panel. But that is deprecated in 10.6

创建NSSavePanel时,如何在不使用不推荐使用的方法的情况下预设文件名?

When creating an NSSavePanel, how can I preset the filename without using the deprecated method?

推荐答案

在运行保存面板之前,请使用10.6中添加的setNameFieldStringValue:方法.如果还要设置默认目录,则需要setDirectoryURL:方法,该方法也已在10.6中添加.

Use the setNameFieldStringValue: method, which was added in 10.6, before running the save panel. If you want to set the default directory too, you will need the setDirectoryURL: method, also added in 10.6.

NSString *defaultDirectoryPath, *defaultName;
NSSavePanel *savePanel;
...
[savePanel setNameFieldStringValue:defaultName];
[savePanel setDirectoryURL:[NSURL fileURLWithPath:defaultDirectoryPath]];
[savePanel runModal];

这篇关于如何在NSSavePanel中预设文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 12:55