FROM : mw
DATE : Sat Jan 18 19:20:39 2003
On 1/18/03 1:05 PM, "Shaun Wexler" <<email_removed>> wrote:
> On Saturday, January 18, 2003, at 09:50 AM, Matis Schotte wrote:
>
>> hi,
>> Which function is called when a window closes? i will bring up a
>> save/dont save dialog when a NSWindow closes by the user ...
>> thx for answers!! :)
>> smat
>
> Add this to your program, in the object in which you wish to perform
> the save/don't save dialog:
>
> [[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification
> object:window];
>
>
> - (void) windowWillClose:(NSNotification *)notification
> {
> NSWindow *windowAboutToClose = [notification object];
>
> if (windowAboutToClose == myWindow)
> [NSApp beginSheet:mySavePanel modalForWindow:myWindow
> modalDelegate:self didEndSelector:@selector(sheetDidEnd:)
> contextInfo:nil];
>
> }
>
> - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
> contextInfo:(void *)contextInfo
> {
> [[NSNotificationCenter defaultCenter] removeObserver:self
> name:NSWindowWillCloseNotification object:window];
>
> // handle the returnCode
> }
No! Don't do that! You never want to override a standard delegate method
with a notification center method!!! If your object is a delegate of the
window that you want to display the save sheet on, then scrap the
NSNotificationCenter code at the top of the above example. If it isn't a
delegate, then change the name of the method to something other than
windowWillClose: for clarity's sake.
mw
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Sat Jan 18 19:20:39 2003
On 1/18/03 1:05 PM, "Shaun Wexler" <<email_removed>> wrote:
> On Saturday, January 18, 2003, at 09:50 AM, Matis Schotte wrote:
>
>> hi,
>> Which function is called when a window closes? i will bring up a
>> save/dont save dialog when a NSWindow closes by the user ...
>> thx for answers!! :)
>> smat
>
> Add this to your program, in the object in which you wish to perform
> the save/don't save dialog:
>
> [[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification
> object:window];
>
>
> - (void) windowWillClose:(NSNotification *)notification
> {
> NSWindow *windowAboutToClose = [notification object];
>
> if (windowAboutToClose == myWindow)
> [NSApp beginSheet:mySavePanel modalForWindow:myWindow
> modalDelegate:self didEndSelector:@selector(sheetDidEnd:)
> contextInfo:nil];
>
> }
>
> - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
> contextInfo:(void *)contextInfo
> {
> [[NSNotificationCenter defaultCenter] removeObserver:self
> name:NSWindowWillCloseNotification object:window];
>
> // handle the returnCode
> }
No! Don't do that! You never want to override a standard delegate method
with a notification center method!!! If your object is a delegate of the
window that you want to display the save sheet on, then scrap the
NSNotificationCenter code at the top of the above example. If it isn't a
delegate, then change the name of the method to something other than
windowWillClose: for clarity's sake.
mw
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Matis Schotte | Jan 18, 18:50 | |
| j o a r | Jan 18, 19:05 | |
| Shaun Wexler | Jan 18, 19:05 | |
| mw | Jan 18, 19:20 | |
| Shaun Wexler | Jan 18, 19:42 | |
| Lachlan Deck | Jan 18, 21:10 | |
| Shaun Wexler | Jan 18, 22:06 | |
| Matis Schotte | Jan 18, 22:29 | |
| Daryn | Jan 19, 04:11 |






Cocoa mail archive

