Amrinder Singh
Amrinder Singh

Reputation: 215

how to handle close button of window in cocoa

I am developing cocoa application having multiple windows. There is a red close button on left corner of window. And I want to handle click event of close button so that I can show message to ask user whether he wants to close window or not. If user accept to close window then application will be terminated otherwise same window shown to user. Any idea how can I handle click event of close button???

Upvotes: 6

Views: 8449

Answers (2)

Devarshi
Devarshi

Reputation: 16758

Please look at NSWindowDelegate protocol reference, the method which you are looking for is-

- (BOOL)windowShouldClose:(id)sender

Upvotes: 13

dafi
dafi

Reputation: 3532

NSWindowController has a method

- (BOOL)shouldCloseDocument

Upvotes: 0

Related Questions