【问题标题】:How to change a deprecated beginSheetForDirectory method如何更改已弃用的 beginSheetForDirectory 方法
【发布时间】:2012-07-07 15:49:38
【问题描述】:

我有一个使用 beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo: 的应用。

我查看了 Apple 文档,该文档说它已被弃用并改用另一种方法:

将保存面板显示为具有指定路径的工作表,并且, 可选地,该路径中的指定文件。 (在 Mac OS X 中已弃用 v10.6。请改用 beginSheetModalForWindow:completionHandler:。)

我的问题是如何将此代码更改为新代码?

//  [savePanel setRequiredFileType:@"png"];
[savePanel beginSheetForDirectory:nil 
                             file:nil  
                   modalForWindow:[self window] 
                    modalDelegate:self 
                   didEndSelector:@selector(didEndSaveSheet:returnCode:conextInfo:) 
                      contextInfo:NULL];

【问题讨论】:

    标签: objective-c cocoa xcode4.3 nssavepanel


    【解决方案1】:

    您正在寻找beginSheetModalForWindow:completionHandler: 方法。

    例子:

    NSSavePanel *savePanel = [NSSavePanel savePanel];
    
    [savePanel beginSheetModalForWindow:_window completionHandler:^(NSInteger result) {
        if (result == NSFileHandlingPanelOKButton) {
            NSURL *savePath = [[savePanel URLs] objectAtIndex:0];
        } else {
            [savePanel close];
        }
    }];
    

    【讨论】:

    • 谢谢安妮,试过了,但是当我在应用程序中测试保存时它只是冻结了所以我想我必须继续玩它直到它工作正常。
    • 好的,我知道为什么它不起作用但不知道该怎么做,之前使用的代码用于从另一个语句中添加的另一个方法中获取 if 条件,是吗是否可以在 if 语句中的旧代码中添加类似 didEndSelector:@selector(didEndSaveSheet:returnCode:conextInfo:) 的内容?
    • [savePanel 关闭];不需要
    猜你喜欢
    • 2016-04-09
    • 2015-05-01
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    相关资源
    最近更新 更多