【问题标题】:Preventing the "Do you want to save the changes" dialog in a macOS app in Swift在 Swift 的 macOS 应用程序中防止“你想保存更改”对话框
【发布时间】:2017-06-24 00:44:28
【问题描述】:

在基于文档的 macOS 项目中,我想避免

“您要保存您在“无标题”文档中所做的更改吗?“如果您不保存更改,您的更改将会丢失。”

消息。

我正在着手实施这个解决方案Preventing the "Save on Exit" dialogue on exit of a Cocoa Document Application

import Cocoa

    class Document: NSDocument {

        var myDoc = MyDoc()

        func isDocumentEdited() -> Bool {
            return false
        }

    }

但我得到了错误:

使用 Objective-C 选择器的方法 'isDocumentEdited()' 'isDocumentEdited' 与来自 'documentEdited' 的 getter 冲突 具有相同 Objective-C 选择器的超类“NSDocument”

我可以做些什么来解决这个错误?

【问题讨论】:

  • 如果你也不想要脏点,覆盖 updateChangeCount(_:) 而不是 isDocumentEdited 并且什么也不做;

标签: cocoa nsdocument


【解决方案1】:

除非您从窗口类调用 isDocumentEdited,否则您可能想要这样做:

class Document: NSDocument {

   var myDoc = MyDoc()

    override var isDocumentEdited: Bool {
        return false
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多