问题
In my mac app I'm using NSSavePanel
- but it's behaving very strange. Sometimes I can't change the default name of the file.
I'm using it like this:
NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setAllowedFileTypes:@[@"jpg"]];
[savePanel setLevel:CGShieldingWindowLevel()];
if([savePanel runModal] == NSFileHandlingPanelOKButton)
{
//saving file
}
I can't find why sometimes it lets me change the file name and other times no, I can save a file but a changing name in save panel is blocked
回答1:
Have you tried providing a default name?
[savePanel setNameFieldStringValue:@"New File.txt"];
回答2:
Swift 4
let panel = NSSavePanel()
panel.nameFieldStringValue = "filename.txt" // <-- user editable prompt
if panel.runModal() == NSApplication.ModalResponse.OK, let url = panel.url {
// use url path here
}
来源:https://stackoverflow.com/questions/29669048/nssavepanel-cant-change-file-name