How to handle window close button in cocoa

I am developing a cocoa application that has multiple windows. In the left corner of the window there is a red button. And I want to process the click of the close button so that I can show the message to ask the user if he wants to close the window or not. If the user accepts to close the window, then the application will be terminated otherwise in the same window that is displayed to the user. Any idea how I can handle a button click close button

+5
source share
2 answers

Check out the link to the NSWindowDelegate protocol , the method you are looking for is

- (BOOL)windowShouldClose:(id)sender
+11
source

NSWindowController has a method

- (BOOL)shouldCloseDocument
0

All Articles