我的应用程序运行在用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.问题是,我正在使用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);
}
}有人知道这是怎么回事吗?
发布于 2020-08-28 18:35:17
如果你换掉
if ([savePanel runModal]==NSModalResponseOK)
...使用
[savePanel beginWithCompletionHandler:^(NSModalResponse result) {
if (result==NSFileHandlingPanelOKButton)
...
}];信息就会消失。
我想这是鼓励使用更现代API的一种微妙的方式。
唯一的问题是,消息是错误的,runModal不受欢迎,而且在任何地方都没有提到或记录这一点。这些天来,这似乎是正常的。:(
https://stackoverflow.com/questions/63622786
复制相似问题