1 year ago

#257450

test-img

techno

windowShouldClose event not triggered after setting delegate

I need to check if the user has clicked the close button and show an alert before closing the form.If the user selects an option the program should not be terminated. For this, I'm doing the following

Setting the delegate in viewDidAppear()

class ViewController: NSViewController, NSWindowDelegate {
   override func viewDidAppear() {
        self.view.window?.delegate = self
    }
}

This is the windowShouldClose event, but this is not getting triggered.

func windowShouldClose(_ : Any) -> Bool {
     //dostuff 
     }

swift

macos

nsview

nswindow

0 Answers

Your Answer

Accepted video resources