Newbie Question re: callback signatures

2010-06-04 Thread Brad Stone
How do I create the callback method?  I don't understand what the signature is 
telling me.  I have 
canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: in my NSDocument 
and I want to set up the callback method.  When I create a method as below it 
never fires.  I must just not be reading it correctly.  

- (void)document:(NSDocument *)doc shouldClose:(BOOL)shouldClose 
contextInfo:(void *)contextInfo {
NSLog(@hey, it finally worked!);
}

What exactly should the method be in my NSDocument?


Thanks in advance.


canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:
If the receiver is not dirty, this method immediately calls the 
shouldCloseSelector callback on the specified delegate with YES.

- 
(void)canCloseDocumentWithDelegate:(id)delegateshouldCloseSelector:(SEL)shouldCloseSelector
 contextInfo:(void *)contextInfo

Parameters
delegate
The delegate to which the selector message is sent.
shouldCloseSelector
The selector of the message sent to the delegate.
contextInfo
Object passed with the callback to provide any additional context information.
Discussion
If the receiver is dirty, an alert is presented giving the user a chance to 
save, not save, or cancel. If the user chooses to save, this method saves the 
document. If the save completes successfully, this method calls the callback 
with YES. If the save is canceled or otherwise unsuccessful, this method calls 
the callback with NO. This method may be called 
byshouldCloseWindowController:delegate:shouldCloseSelector:contextInfo:. It is 
also called by the NSDocumentController method closeAllDocuments. You should 
call it before you call closeif you are closing the document and want to give 
the user a chance to save any edits. Pass thecontextInfo object with the 
callback.
The shouldCloseSelector callback method should have the following signature:
- (void)document:(NSDocument *)doc shouldClose:(BOOL)shouldClose  
contextInfo:(void  *)contextInfo
Availability
Available in Mac OS X v10.0 and later.
Declared In
NSDocument.h

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Newbie Question re: callback signatures

2010-06-04 Thread Quincey Morris
On Jun 4, 2010, at 13:03, Brad Stone wrote:

 How do I create the callback method?  I don't understand what the signature 
 is telling me.  I have 
 canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: in my 
 NSDocument and I want to set up the callback method.  When I create a method 
 as below it never fires.  I must just not be reading it correctly.  
 
 - (void)document:(NSDocument *)doc shouldClose:(BOOL)shouldClose 
 contextInfo:(void *)contextInfo {
   NSLog(@hey, it finally worked!);
 }
 
 What exactly should the method be in my NSDocument?

It's a bit confusing, because your 'canCloseDocumentWithDelegate...' is an 
override. That means a delegate selector is being passed *in* to this method, 
and it's not your selector. There's no direct way to substitute your 
'document:shouldClose:...' method for the supplied one.

But there is a solution. Look in the Leopard AppKit Developer Release Note:


http://developer.apple.com/mac/library/releasenotes/Cocoa/AppKitOlderNotes.html

in the section with the following title:

Advice for Overriders of Methods that Follow the 
delegate:didSomethingSelector:contextInfo: Pattern

This explains what you need to do to get your method to be called.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com