【问题标题】:Removing RepresentedFilename From Window Through NSWindowController通过 NSWindowController 从窗口中删除 RepresentedFilename
【发布时间】:2018-06-21 02:20:49
【问题描述】:

我知道我们可以通过窗口控制器 (NSWindowController) 为窗口 (NSWindow) 设置一个带有通用图标的表示文件名。

class MyWindowController: NSWindowController {
    @objc func setTitleFileName(notification: NSNotification) {
        // myWindow is an IBOutlet object to a window (`NSWindow`), path is a file path
        if let path = notification.object as? String {
            myWindow.setTitleWithRepresentedFilename(path)
        }
    }
}

所以我得到一个文件名 (Test.mov) 作为代表文件名。我在一个视图控制器 (NSViewController) 中设置了一个文件。当应用程序转换到另一个应用程序时,我想将其删除并重新设置应用程序名称。但它看起来不像我可以删除它。如果我只是为窗口设置一个字符串,例如

myWindow.title = "Application"

,通用图标仍将保留。我不能将 nil 设置为 setTitleWithRepresentedFilename。完成后有什么方法可以删除通用文件图标吗?谢谢。

【问题讨论】:

    标签: swift cocoa nswindow nswindowcontroller


    【解决方案1】:
    myWindow.representedFilename = ""
    

    myWindow.setTitleWithRepresentedFilename("")
    

    将删除图标。

    【讨论】:

    • 一个空的文件路径...为什么我没想到呢?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多