小编cal*_*n63的帖子

windowShouldClose(_:) 委托函数未在代码中调用

我目前正在尝试通过一本 Mac Apps 书籍来学习 Cocoa,其中一个程序具有 windowShouldClose(_:) 委托函数。但是,当我运行该程序时,只要调用该函数,窗口仍然会关闭。程序仍在运行,但窗口关闭。谁能解释为什么会发生这种情况?这是我的代码:

import Cocoa

class MainWindowController: NSWindowController, NSSpeechSynthesizerDelegate, NSWindowDelegate {

@IBOutlet weak var textField: NSTextField!
@IBOutlet weak var speakButton: NSButton!
@IBOutlet weak var stopButton: NSButton!

let speechSynth = NSSpeechSynthesizer()

var isStarted: Bool = false {
    didSet {
        updateButtons()
    }
    }

override var windowNibName: String {
    return "MainWindowController"
}

override func windowDidLoad() {
    super.windowDidLoad()
    updateButtons()
    speechSynth.delegate = self
}

//MARK: - Action methods

//get typed-in text as string
@IBAction func speakIt(sender: NSButton){
    let string = textField.stringValue …
Run Code Online (Sandbox Code Playgroud)

cocoa swift

3
推荐指数
1
解决办法
2065
查看次数

标签 统计

cocoa ×1

swift ×1