【发布时间】:2020-08-27 19:13:22
【问题描述】:
在使用 Xcode 11.1 构建的 macOS 10.15.6 中运行时,当我显示保存对话框时,我的应用突然(至少我刚刚注意到)在控制台上吐出这些警告:
WARNING: <NSSavePanel: 0x100e43250> found it necessary to prepare implicitly; please prepare panels using NSSavePanel rather than NSApplication or NSWindow.
WARNING: <NSSavePanel: 0x100e43250> found it necessary to start implicitly; please start panels using NSSavePanel rather than NSApplication or NSWindow.
WARNING: <NSSavePanel: 0x100e43250> running implicitly; please run panels using NSSavePanel rather than NSApplication.
问题是,我 am 使用 NSSavePanel 来呈现此对话框。这是整个方法。我看不出它有什么问题。我没有使用任何已弃用的方法。 (如果我遇到问题,window 是 nil,所以 runModel 会被调用。)
/** Present a modal dialog (window==nil) or begin a sheet (window!=nil) that prompts the user to create a new archive.
*
* Attaches the rundancy picker view to the save panel so the user can choose the redundancy level.
* Presents a warning if the user picks a volume that has size limitations.
* If successful, invokes the handler with the URL of the new repository and its creation settings.
* @param window window for sheet, or nil for modal dialog
* @param title optional title
* @param name optional default name
* @param directory optional default directory
* @param handler completion handler
*/
+ (void)newArchivePrompForWindow:(nullable NSWindow *)window
withTitle:(nullable NSString*)title
name:(nullable NSString*)name
inDirectory:(nullable NSURL*)directory
completionHandler:(void (^)(NSURL* repositoryURL, NSDictionary* settings))handler
{
NSSavePanel* savePanel = [NSSavePanel savePanel];
savePanel.title = ( title ?: @"New Archive" );
savePanel.allowedFileTypes = @[kRepositoryFileType];
// savePanel.canSelectHiddenExtension = YES;
savePanel.extensionHidden = YES;
savePanel.prompt = @"Create";
savePanel.nameFieldLabel = @"Archive:";
if (directory!=nil)
savePanel.directoryURL = directory; // set optional default folder
if (name!=nil)
savePanel.nameFieldStringValue = name; // set optional name
// attach the redundancy picker controller
RepositoryPickRedundancyViewController* redundancyAccessoryController;
redundancyAccessoryController = [[RepositoryPickRedundancyViewController alloc] initWithNibName:@"RepositoryPickRedundancyView"
bundle:nil];
[savePanel setAccessoryView:redundancyAccessoryController.view];
redundancyAccessoryController.version = kDataRedundancyPickerSchemeDefault;
redundancyAccessoryController.configurationIndex = kDataRedundancyPickerConfigIndexDefault;
// Present the panel
if (window!=nil)
{
// The dialog is attached to a window
// Present a sheet attached to the window
[savePanel beginSheetModalForWindow:window completionHandler:^(NSInteger result) {
if (result==NSFileHandlingPanelOKButton)
// User picked an archive: vet it and continue
NewArchivePostProcessing(savePanel,window,redundancyAccessoryController,savePanel.URL,handler);
else
// canceled
handler(nil,nil);
}];
}
else
{
// No parent window: run a modal dialog
if ([savePanel runModal]==NSModalResponseOK)
// User picked an archive: vet it and continue
NewArchivePostProcessing(savePanel,nil,redundancyAccessoryController,savePanel.URL,handler);
else
// canceled
handler(nil,nil);
}
}
有人知道这里发生了什么吗?
【问题讨论】:
-
嗨,有趣,不确定这是否会引起兴趣developer.apple.com/forums/thread/655939
-
已经看到那个帖子了;它没有回答问题
-
我试过你的代码(没有
RepositoryPickRedundancyViewController),但我没有收到警告。 -
你是对的,如果我删除
setAccessoryView语句,保存对话框会运行而不记录任何警告。但这仍然不应该发生。
标签: macos cocoa nssavepanel